using a proxy with urllib2

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lee, Dustin

    using a proxy with urllib2

    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.ProxyHa ndler({"http":" http://webproxy.mycomp any.com:3128"})
    #proxy_support = urllib2.ProxyHa ndler()
    opener = urllib2.build_o pener(proxy_sup port)
    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.mycomp any.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.mycomp any.com:3128 lynx http://some.site.com/
    or
    export http_proxy=http ://webproxy.mycomp any.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

Working...