468,309 Members | 1,113 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,309 developers. It's quick & easy.

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

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.

Apr 9 '06 #1
4 6834

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.


Apr 9 '06 #2
thanks, I will try pycurl.

Apr 10 '06 #3
"Ju Hui" <ph*****@gmail.com> 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/dr...ForPython.html
And monkeypatch urllib2 (and everything else that uses module socket!)
something like so (UNTESTED):

import sys, os

os.environ['SOCKS_SERVER'] = 'joe:pa******@proxy.example.org'
import SOCKS
from socket import getfqdn
SOCKS.getfqdn = getfqdn
sys.modules['socket'] = SOCKS
del getfqdn, SOCKS

import urllib2
then just use urllib2 normally...

John

Apr 12 '06 #4
thanks a lot!

Apr 13 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by O. Koch | last post: by
4 posts views Thread by bmiras | last post: by
1 post views Thread by Ray Slakinski | last post: by
1 post views Thread by tomazi75-nospam(at)gmail.com | last post: by
6 posts views Thread by Alejandro Dubrovsky | last post: by
3 posts views Thread by itay_k | last post: by
1 post views Thread by Alessandro Fachin | last post: by
6 posts views Thread by Jack | last post: by
1 post views Thread by Magnus.Moraberg | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.