using a proxy with urllib2

Lee, Dustin dlee at rightnow.com
Fri Mar 19 13:21:10 EST 2004


I'm using python2.2.2 on redhat linux 7.3

Here's a snippet of what I'm trying to run:

# set up proxy
import urllib2
proxy_support = urllib2.ProxyHandler({"http":"http://webproxy.mycompany.com:3128"})
#proxy_support = urllib2.ProxyHandler()
opener = urllib2.build_opener(proxy_support)
urllib2.install_opener(opener)
f = urllib2.urlopen('http://some.site.com/')
print f.read(1000)
    
This code times out and throws a socket connection error.  I've also tried setting my environment variable: http_proxy=http://webproxy.mycompany.com:3128 and using the default form of ProxyHandler.

I'm certain the proxy info is correct (and a proxy is needed) because I can use lynx to get it to work:

env http_proxy=http://webproxy.mycompany.com:3128 lynx http://some.site.com/
or
export http_proxy=http://webproxy.mycompany.com:3128 
lynx http://some.site.com/

Without the proxy info defined for lynx it won't connect to the site in question.

Any ideas what might be tripping me up?

dustin




More information about the Python-list mailing list