Python urllib2 HTTPS and proxy NTLM authentication

冷暖自知 提交于 2019-12-19 07:41:11

问题


urllib2 doesn't seem to support HTTPS with proxy authentication in general, even less with NTLM authentication. Anyone knows if there is a patch somewhere for HTTPS on proxy with NTLM authentication.

Regards,

Laurent


回答1:


Late reply. Urllib2 does not support NTLM proxying but pycurl does. Excerpt:

self._connection = pycurl.Curl()
self._connection.setopt(pycurl.PROXY, PROXY_HOST)
self._connection.setopt(pycurl.PROXYPORT, PROXY_PORT)
self._connection.setopt(pycurl.PROXYUSERPWD,
                        "%s:%s" % (PROXY_USER, PROXY_PASS))
...



回答2:


http://code.google.com/p/python-ntlm/

I never tried with HTTPS but I think it should work.

EDIT: If you are using SSL Tunneling, proxy authentication is a bad idea.

Proxy using Basic Auth over HTTPS is not secure when the SSL is tunneled. Your password will be sent in clear (Base64-encoded) to proxy. Lots of people assumes the password will be encrypted inside SSL. It's not true in this case.

It's almost impossible to support other encrypted or hashed mechanisms like Digest/NTLM because they all require negotiation (multiple exchanges) and that's not defined in CONNECT protocol. This negotiation happens out of the band of the HTTP connection. It's very hard to implement in proxy/browser also.

If this is an enterprise proxy, IP ACL is the only secure solution.




回答3:


Good recipe (for HTTPS w/proxy) and discussion here, it should be possible to meld that with the python-nltm code @ZZ has already suggested.



来源:https://stackoverflow.com/questions/1481398/python-urllib2-https-and-proxy-ntlm-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!