urllib fails to connect

jlist nospam at invalid.com
Thu Aug 21 01:46:06 EDT 2008


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.






More information about the Python-list mailing list