无法使用urllib和代理访问网站

2024-04-20 13:00:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我用ssh -D localhost:5678 me@server.com打开了一个ssh隧道,我想在python3应用程序中使用它。在

#!/usr/bin/python3.1
# -*- coding:Utf-8 -*-

import urllib.request

proxyhand = urllib.request.ProxyHandler({"socks" : "http://localhost:5678"})
opener = urllib.request.build_opener(proxyhand)
page = opener.open("http://www.mysite.com")

在哪里mysite.com网站只能从上的网络访问服务器网站(这就是为什么我使用ssh隧道)。在

它可以访问任何其他网站,没有任何限制,但mysite.com网站我有一个连接超时错误。我可以进入隧道mysite.com网站使用firefox配置的as explained here。在

谢谢你


Tags: com应用程序localhosthttpserver网站requestopener
1条回答
网友
1楼 · 发布于 2024-04-20 13:00:51

您应该使用http作为协议,而不是{}?因此:

proxyhand = urllib.request.ProxyHandler({"http" : "http://localhost:5678"})

相关问题 更多 >