0
我想用urllib2和polipo來使用Tor。我需要的是在程序運行時切換到特定的出口節點的方法。 我已在 'AllowDotExit 1' 的/ etc /符/的torrc,並嘗試以下方法:Tor。從波爾圖退出urllib2
import urllib2
proxy = '127.0.0.1'
port = '8118'
url='http://ifconfig.me.651d7ace80e0b53e6c05eb4db2491264f049df66.exit'
proxyurl = '%s:%s' % (proxy, port)
proxyhandler = urllib2.ProxyHandler({'http': proxyurl})
opener = urllib2.build_opener(proxyhandler)
page = opener.open(url)
print 'Page opened.'
print page.read()
但是我得到的是:
:!/usr/bin/env python tortest.py
Traceback (most recent call last):
File "tortest.py", line 18, in <module>
page = opener.open(url, timeout=20)
File "/usr/lib/python2.7/urllib2.py", line 406, in open
response = meth(req, response)
File "/usr/lib/python2.7/urllib2.py", line 519, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python2.7/urllib2.py", line 444, in error
return self._call_chain(*args)
File "/usr/lib/python2.7/urllib2.py", line 378, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 527, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 504: Connect to ifconfig.me.651d7ace80e0b53e6c05eb4db2491264f049df66.exit:80 failed: General SOCKS server failure
誰能幫我嗎?