How can I setup proxy of urllib2 properly

N

Neil.Jin

I got some source code form python's help document. the below:

proxy_handler = urllib2.ProxyHandler({'http':
'http://www.example.com:3128/'})
proxy_auth_handler = urllib2.HTTPBasicAuthHandler()
proxy_auth_handler.add_password('realm', 'host', 'username',
'password')
^^^^^^^ ^^^^^

opener = urllib2.build_opener(proxy_handler, proxy_auth_handler)
# This time, rather than install the OpenerDirector, we use it
directly:
opener.open('http://www.example.com/login.html')

I have only the username and password of proxy server. But I do not
know what should I provide for the 'realm' and 'host' prameters of
add_password function.

for example,
My proxy server is "www.myproxy.com"
username is "user1"
password is "pass1"

how can I provide parameters for "add_password" function?
 

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,968
Messages
2,570,154
Members
46,701
Latest member
XavierQ83

Latest Threads

Top