urllib2.ProxyHandler

Discussion in 'Python' started by rx, Apr 18, 2006.

  1. rx

    rx Guest

    I'm trying to hide my IP with the following code:

    import urllib2
    proxy=[urllib2.ProxyHandler({'http':'24.232.167.22:80'})]
    opener=urllib2.build_opener(proxy)
    f=opener.open('http://www.whatismyipaddress.com')
    print f.read()

    But that didn't work - my real IP showed up.

    Then I made the following replacement:

    proxy=[urllib2.ProxyHandler({'http':'24.232.167.22:80'})] ->
    proxy=[urllib2.ProxyHandler({'http':'foo'})]

    And got the exact same result.

    What am I doing wrong ?
    Do I need a name instead of 24.232.167.22 ? (but this IP and some others I
    tried didn't have a name)

    Thanks in advance....
     
    rx, Apr 18, 2006
    #1
    1. Advertising

  2. rx

    John J. Lee Guest

    "rx" <> writes:

    > I'm trying to hide my IP with the following code:
    >
    > import urllib2
    > proxy=[urllib2.ProxyHandler({'http':'24.232.167.22:80'})]
    > opener=urllib2.build_opener(proxy)


    build_opener takes *args, not a list:

    import urllib2
    handlers = [urllib2.ProxyHandler({'http':'24.232.167.22:80'})]
    opener = urllib2.build_opener(*handlers)


    or just:

    import urllib2
    proxy_handler = urllib2.ProxyHandler({'http':'24.232.167.22:80'})
    opener = urllib2.build_opener(proxy_handler)


    Also, IIRC 2.4 does not allow ports in proxy specification strings
    (the values in the dict you pass to ProxyHandler's constructor), and
    IIRC 2.5a1 ProxyHandler is broken (it's fixed in the SVN repository).


    John
     
    John J. Lee, Apr 20, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kylotan

    urllib2 for HTTPS/SSL

    Kylotan, Jul 8, 2003, in forum: Python
    Replies:
    5
    Views:
    578
    Jeremy Hylton
    Jul 9, 2003
  2. John J. Lee

    Re: urllib2 http status

    John J. Lee, Jul 29, 2003, in forum: Python
    Replies:
    1
    Views:
    2,568
    rosendo
    Jul 31, 2003
  3. O. Koch

    FTP with urllib2 behind a proxy

    O. Koch, Aug 7, 2003, in forum: Python
    Replies:
    4
    Views:
    1,327
    John J. Lee
    Aug 14, 2003
  4. Josef Cihal
    Replies:
    0
    Views:
    836
    Josef Cihal
    Sep 5, 2005
  5. Devraj
    Replies:
    3
    Views:
    1,079
    John J. Lee
    Oct 13, 2007
Loading...

Share This Page