469,362 Members | 2,548 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Re: urllib fails to connect

jlist wrote:
>
I found out why. I set a proxy in IE and I didn't know
ActiveState Python use IE proxy!
I'm running ActiveState Python 2.5 on Windows XP. It used
to work fine. Today however I get (10061, 'Connection refused')
for any site I try with urllib.urlopen().
switching to urllib2, installing the proxy opener, worked for me.
here is the sample. variable names are self explanatory

import urllib2
proxy=urllib2.ProxyHandler({"http":'http://'+proxyuser+':'+proxypass+'@'+httpproxy})
opener=urllib2.build_opener(proxy, urllib2.HTTPHandler)
urllib2.install_opener(opener)
req = urllib2.Request(url, form, headers)
fd = urllib2.urlopen(req)
print fd.code, fd.info(), fd.read()

regards
Edwin
The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure. If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof. Thank you.
Aug 20 '08 #1
1 1167
Thanks. My problem was not how to use a proxy server but how
to not use the IE proxy :)

BTW, I'm not a fan of the way urllib2 uses a proxy particularly.
I think it's really unneccesarily complicated. I think it should be
something like this:
def urlopen(url, proxy='')

And if you want to use a proxy, set one in the call.
I found out why. I set a proxy in IE and I didn't know
ActiveState Python use IE proxy!
I'm running ActiveState Python 2.5 on Windows XP. It used
to work fine. Today however I get (10061, 'Connection refused')
for any site I try with urllib.urlopen().
switching to urllib2, installing the proxy opener, worked for me.
here is the sample. variable names are self explanatory

import urllib2
proxy=urllib2.ProxyHandler({"http":'http://'+proxyuser+':'+proxypass+'@'+httpproxy})
opener=urllib2.build_opener(proxy, urllib2.HTTPHandler)
urllib2.install_opener(opener)
req = urllib2.Request(url, form, headers)
fd = urllib2.urlopen(req)
print fd.code, fd.info(), fd.read()

regards
Edwin
The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure. If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof. Thank you.

Aug 21 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by C GIllespie | last post: by
11 posts views Thread by Pater Maximus | last post: by
4 posts views Thread by william | last post: by
6 posts views Thread by JabaPyth | last post: by
reply views Thread by Ali.Sabil | last post: by
4 posts views Thread by kgrafals | last post: by
5 posts views Thread by supercooper | last post: by
5 posts views Thread by John Nagle | last post: by
5 posts views Thread by jlist | last post: by
2 posts views Thread by Iain Dalton | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.