Solved

How do I set up proxy authentication using Python urllib2?

Posted on 2008-10-09
1
4,812 Views
Last Modified: 2012-06-21
I am trying to access a website on my corporate intranet from a Python program.
The intranet is set up to use a proxy server and the proxy server requires authentication.
>>> try:
...       urllib2.urlopen("http://lmaprda01:8080/etc/etc")
... except IOError, e:
...       print e.headers
...       
Via: 1.1 GIPPRDW02
Proxy-Authenticate: Negotiate
Proxy-Authenticate: Kerberos
Proxy-Authenticate: NTLM
Connection: Keep-Alive
Proxy-Connection: Keep-Alive
Pragma: no-cache
Cache-Control: no-cache
Content-Type: text/html
Content-Length: 4112  

I've read the urllib2 howto on python.org but it shows how to authenticate on the site not on the proxy and the proxy example is too sketchy for me to figure it out.
Part of the problem may be that I don't really know my username. Is it Windows-style domain\username or does the domain live in the realm? And if not how can I find out what the realm is?
0
Comment
Question by:PaulKeating
1 Comment
 
LVL 5

Accepted Solution

by:
PaulKeating earned 0 total points
ID: 22685229
A colleague points out that since the url is on the corporate intranet I should not be going through a proxy. Instead I should knock out the proxy handler, which is described in the howto on python.org
>>> proxy_support = urllib2.ProxyHandler({})
>>> opener = urllib2.build_opener(proxy_support)
>>> urllib2.install_opener(opener)
>>> urllib2.urlopen('http:// etc')
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Less strange, but still introduction This introduction was added (1st August, 2011) to reflect some reactions.  Firstly, the term basics in the title of the article...  As any other word, it is a symbol with meaning attached to the word by some a…
Common practice undertaken by most system administrators is to document the configurations and final solutions of anything performed by them for their future use and reference. So here I am going to explain how to export ISA Server 2004 Firewall pol…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question