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支持。你可能需要再跳一圈才能让它工作。试试这个: