Skip to content Skip to sidebar Skip to footer

HTTPS Request Via Urllib2 Fails Behind NTLM Proxy

Via Python's urllib2 I try to get data over HTTPS while I am behind a corporate NTLM proxy. I run proxy_url = ('http://user:pw@ntlmproxy:port/') proxy_handler = urllib2.ProxyHandle

Solution 1:

The problem is that Python's standard HTTP libraries do not speak Microsoft's proprietary NTLM authentication protocol fully.

I solved this problem by setting up a local NTLM-capable proxy - ntlmaps did the trick for me.(*) - which providesthe authentication against the corporate proxy and point my python code to this local proxy without authentication credentials.

Additionally I had to add in the above listed python code a proxy_handler for HTTPS. So I replaced the two lines

proxy_url = 'http://user:pw@ntlmproxy:port/' 
proxy_handler = urllib2.ProxyHandler({'http': proxy_url})

with the two lines

proxy_url = 'http://localproxy:localport/' 
proxy_url_https = 'https://localproxy:localport/' 
proxy_handler = urllib2.ProxyHandler({'http': proxy_url, 'https': proxy_url_https})

Then the request works perfectly.


(*) ntlmaps is a Python program. Due to some reasons in my personal environment it was for me necessary that the proxy is a python program.)


Post a Comment for "HTTPS Request Via Urllib2 Fails Behind NTLM Proxy"