I'm working on learning how to use urllib2 to use a proxy server. I've
looked through the postings on this group, and it's been helpful. I
have not, however, found complete documentation on the add_password()
functions. Here's what I've got so far:
#============== =============== ===========
import urllib2
url = 'http://some.server/form.php'
proxy_url = 'http://202.62.252.3:80 80' # A publicly available anonymous
proxy server
proxy_handler = urllib2.ProxyHa ndler( {'http': proxy_url } )
proxy_auth_hand ler = urllib2.HTTPBas icAuthHandler()
proxy_auth_hand ler.add_passwor d('realm', 'host', 'username',
'password')
opener = urllib2.build_o pener(proxy_han dler, proxy_auth_hand ler)
urllib2.install _opener(opener)
try:
handler = urllib2.urlopen (url)
except urllib2.URLErro r:
print "whoops!"
else:
print handler.read()
#============== =============== ==========
It works, but I don't really know what I'm doing with the
proxy_auth_hand ler part. Specifying username and password make sense,
but I haven't found documentation on what 'realm' and 'host' are for.
Shouldn't username & password be sufficient?
Thanks,
--Steve (mrstephengross @hotmail.com)
looked through the postings on this group, and it's been helpful. I
have not, however, found complete documentation on the add_password()
functions. Here's what I've got so far:
#============== =============== ===========
import urllib2
url = 'http://some.server/form.php'
proxy_url = 'http://202.62.252.3:80 80' # A publicly available anonymous
proxy server
proxy_handler = urllib2.ProxyHa ndler( {'http': proxy_url } )
proxy_auth_hand ler = urllib2.HTTPBas icAuthHandler()
proxy_auth_hand ler.add_passwor d('realm', 'host', 'username',
'password')
opener = urllib2.build_o pener(proxy_han dler, proxy_auth_hand ler)
urllib2.install _opener(opener)
try:
handler = urllib2.urlopen (url)
except urllib2.URLErro r:
print "whoops!"
else:
print handler.read()
#============== =============== ==========
It works, but I don't really know what I'm doing with the
proxy_auth_hand ler part. Specifying username and password make sense,
but I haven't found documentation on what 'realm' and 'host' are for.
Shouldn't username & password be sufficient?
Thanks,
--Steve (mrstephengross @hotmail.com)
Comment