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

J

Ju Hui

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.
 
F

Fuzzyman

Ju said:
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
 
J

John J. Lee

Ju Hui said:
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[email protected]'
import SOCKS
from socket import getfqdn
SOCKS.getfqdn = getfqdn
sys.modules['socket'] = SOCKS
del getfqdn, SOCKS

import urllib2


then just use urllib2 normally...



John
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top