468,269 Members | 1,568 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,269 developers. It's quick & easy.

set_proxy in urllib2 is driving my crazy

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
1 4138
* 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.

Similar topics

4 posts views Thread by dont bother | last post: by
2 posts views Thread by John F Dutcher | last post: by
reply views Thread by Shapper | last post: by
1 post views Thread by Miguel Dias Moura | last post: by
5 posts views Thread by Pupeno | last post: by
1 post views Thread by Alessandro Fachin | last post: by
3 posts views Thread by rashpal.sidhu | last post: by
5 posts views Thread by mark4asp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.