Using urlopen with a proxy server requiring authentication
Dick Streefland
dick.streefland at tasking.com
Mon Apr 2 12:01:29 EDT 2001
egmanoj at yahoo.com wrote:
| Hello,
| I am trying to use the Python(1.5) urllib module's urlopen method to
| retrieve an xml file from a website. The request has to go through
| our LAN's proxy server and this needs a username and password.
|
| How can I automatically supply the username and password while using
| this from a script? [There is no problem while using urlopen from the
| IDLE; the prompt comes up and I just have to type in the username and
| password]
For a proxy authorization, you need to send an additional
"Proxy-authorization" header with the base64 "encryption" of your
username and password. I don't think you can do that with urllib,
but you can use the httplib module instead:
import binascii
cookie = binascii.b2a_base64("username:password")
...
h.putheader('Proxy-authorization', 'Basic %s' % cookie)
--
Dick Streefland //// TASKING Software BV
dick.streefland at tasking.com (@ @) http://www.tasking.com
--------------------------------oOO--(_)--OOo---------------------------
More information about the Python-list
mailing list