2012-06-10 177 views
10

我正在嘗試使用python進行HTTP請求。我試圖改變我的Windows系統代理(使用inetcpl.cpl如何使用python通過(tor)socks代理髮出HTTP請求?

url = 'http://www.whatismyip.com' 
request = urllib2.Request(url) 
request.add_header('Cache-Control','max-age=0') 
request.set_proxy('127.0.0.1:9050', 'socks') 
response = urllib2.urlopen(request) 
response.read() 

是給我的錯誤

Traceback (most recent call last): File "", line 1, in response = urllib2.urlopen(request) File "C:\Python27\lib\urllib2.py", line 126, in urlopen return _opener.open(url, data, timeout) File "C:\Python27\lib\urllib2.py", line 400, in open response = self._open(req, data) File "C:\Python27\lib\urllib2.py", line 423, in _open 'unknown_open', req) File "C:\Python27\lib\urllib2.py", line 378, in _call_chain result = func(*args) File "C:\Python27\lib\urllib2.py", line 1240, in unknown_open raise URLError('unknown url type: %s' % type) URLError:

+0

可能重複:http://stackoverflow.com/questions/2317849/how-can-i-use-a-socks-4-5- proxy-with-urllib2/8100870#8100870 – claws

回答

相關問題