By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,087 Members | 947 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,087 IT Pros & Developers. It's quick & easy.

set_proxy in urllib2 is driving my crazy

P: n/a
est
A simple py script

import urllib2
req=urllib2.Request("http://www.google.com")
req.set_proxy("127.0.0.1:1","http")
print urllib2.urlopen(req).read()


Here is error:

"C:\Python25\python.exe" -u "E:\Python\Crawler\test.py"
Traceback (most recent call last):
File "E:\Python\Crawler\test.py", line 4, in <module>
print urllib2.urlopen(req).read()
File "C:\Python25\lib\urllib2.py", line 121, in urlopen
return _opener.open(url, data)
File "C:\Python25\lib\urllib2.py", line 374, in open
response = self._open(req, data)
File "C:\Python25\lib\urllib2.py", line 392, in _open
'_open', req)
File "C:\Python25\lib\urllib2.py", line 353, in _call_chain
result = func(*args)
File "C:\Python25\lib\urllib2.py", line 1101, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "C:\Python25\lib\urllib2.py", line 1076, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error (10054, 'Connection reset by peer')>
I built a proxy with CCproxy 6.3.2 on my own machine, and it's working
absolutely all right, but how can my simple python script go wrong ?

Jul 23 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
* est <el***********@gmail.com[2007-07-23 09:50:17]:
A simple py script

import urllib2
req=urllib2.Request("http://www.google.com")
req.set_proxy("127.0.0.1:1","http")
print urllib2.urlopen(req).read()
Try to use the ProxyHandler of urllib2.

import urllib2
proxy_url = 'http://' + PROXY_USER + ':' + PROXY_PASSWORD + \ '@' + PROXY_IP + ':' + PROXY_PORT
proxy_support = urllib2.ProxyHandler({'http': proxy_url})
opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler)
urllib2.install_opener(opener)
print urllib2.urlopen(req).read()
urllib2.URLError: <urlopen error (10054, 'Connection reset by peer')>
The error indicates a network issue. Please see the difference when you use
the ProxyHandler to try it.
--
O.R.Senthil Kumaran
http://uthcode.sarovar.org
Jul 24 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.