I wanna use urllib2 to get a page with a socks 5 proxy,who can give me a sample code ?

Discussion in 'Python' started by Ju Hui, Apr 9, 2006.

  1. Ju Hui

    Ju Hui Guest

    I wanna use urllib2 to get a page with a socks 5 proxy,who can give me
    a sample code ?

    example,
    the proxy server is :123.123.123.123
    and the port is :1080
    and the username/password is : user/pass
    I want to open http://www.google.com

    how to write this kind of script?
    thanks.
     
    Ju Hui, Apr 9, 2006
    #1
    1. Advertising

  2. Ju Hui

    Fuzzyman Guest

    Ju Hui wrote:
    > I wanna use urllib2 to get a page with a socks 5 proxy,who can give me
    > a sample code ?
    >
    > example,
    > the proxy server is :123.123.123.123
    > and the port is :1080
    > and the username/password is : user/pass
    > I want to open http://www.google.com
    >
    > how to write this kind of script?

    I'm pretty sure that urllib2 doesn't work with SOCKS proxies of any
    kind.

    I think you'll have to use pycurl (extension library - not in standard
    lib). This is mcuh more powerful, but not so simple to use.

    All the best,

    Fuzzyman
    http://www.voidspace.org.uk/python/index.shtml

    > thanks.
     
    Fuzzyman, Apr 9, 2006
    #2
    1. Advertising

  3. Ju Hui

    Ju Hui Guest

    thanks, I will try pycurl.
     
    Ju Hui, Apr 10, 2006
    #3
  4. Ju Hui

    John J. Lee Guest

    "Ju Hui" <> writes:

    > I wanna use urllib2 to get a page with a socks 5 proxy,who can give me
    > a sample code ?

    [...]

    I haven't used it myself (though curiously, ftplib knows about this
    module and will use it if present -- and urllib2 uses ftplib to fetch
    ftp: URLs), but you could try this

    http://www.w3.org/People/Connolly/drafts/socksForPython.html


    And monkeypatch urllib2 (and everything else that uses module socket!)
    something like so (UNTESTED):

    import sys, os

    os.environ['SOCKS_SERVER'] = 'joe:p'
    import SOCKS
    from socket import getfqdn
    SOCKS.getfqdn = getfqdn
    sys.modules['socket'] = SOCKS
    del getfqdn, SOCKS

    import urllib2


    then just use urllib2 normally...



    John
     
    John J. Lee, Apr 12, 2006
    #4
  5. Ju Hui

    Ju Hui Guest

    Re: I wanna use urllib2 to get a page with a socks 5 proxy, who can give me a sample code ?

    thanks a lot!
     
    Ju Hui, Apr 13, 2006
    #5
    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. Kevin

    Socks proxy library

    Kevin, Dec 13, 2003, in forum: Java
    Replies:
    0
    Views:
    856
    Kevin
    Dec 13, 2003
  2. Chorg
    Replies:
    1
    Views:
    1,452
    A Baba
    Dec 13, 2003
  3. vidy5300
    Replies:
    0
    Views:
    872
    vidy5300
    Jun 7, 2004
  4. Barney
    Replies:
    1
    Views:
    2,037
    jainjani
    Jul 25, 2006
  5. Shumkov

    GET request with socks proxy

    Shumkov, Jul 5, 2007, in forum: Ruby
    Replies:
    0
    Views:
    164
    Shumkov
    Jul 5, 2007
Loading...

Share This Page