Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法使用urllib和代理访问网站_Python_Proxy_Urllib_Ssh Tunnel - Fatal编程技术网

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

Python 无法使用urllib和代理访问网站,python,proxy,urllib,ssh-tunnel,Python,Proxy,Urllib,Ssh Tunnel,我已经用ssh-D localhost:5678打开了一个ssh隧道me@server.com我想在我的python3应用程序中使用它 #!/usr/bin/python3.1 # -*- coding:Utf-8 -*- import urllib.request proxyhand = urllib.request.ProxyHandler({"socks" : "http://localhost:5678"}) opener = urllib.request.build_opener(

我已经用
ssh-D localhost:5678打开了一个ssh隧道me@server.com
我想在我的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只能从server.com上的网络访问(这就是我使用ssh隧道的原因)

它可以无限制地访问任何其他网站,但对于mysite.com,我有一个连接超时错误。我可以使用配置好的firefox访问mysite.com,因此隧道可以正常工作


谢谢

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

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

对于“http”,我对任何网站都有一个“BadStatusLine”异常。SOCKS对于SSH重定向是正确的。我认为问题在于
urllib
没有SOCKS支持。你可能需要再跳一圈才能让它工作。试试这个: