ntlm authentication for urllib2

  • Thread starter Jorge Alberto Diaz Orozco
  • Start date
J

Jorge Alberto Diaz Orozco

Hi there:
I'm working with urllib2 to open some urls and grab some data. The url
will be inserted by the user and my script will open it and parse the
page for results.
the thing is I'm behind a ntlm proxy, and I've tried with a lot of
things to authenticate but it still doesn't work at all.
I did some research and found pytho-ntlm but I'm not sure how to use it.


I wrote something like this and it still giving me an authentication error:
Can someone help me???

import urllib2
from HTTPNtlmAuthHandler import HTTPNtlmAuthHandler
url = 'http://url.i.want.to.parse'
user = u'DOMAIN\\myuser'
password = 'mypass'

passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, url, user , password)
auth_NTLM = HTTPNtlmAuthHandler(passman)
proxy_handler = urllib2.ProxyHandler({'http': 'http://10.0.0.1:8080'})

opener = urllib2.build_opener(proxy_handler, auth_NTLM)
urllib2.install_opener(opener)

response = urllib2.urlopen(url)

print 'done'
print(response.read())

10mo. ANIVERSARIO DE LA CREACION DE LA UNIVERSIDAD DE LAS CIENCIAS INFORMATICAS...
CONECTADOS AL FUTURO, CONECTADOS A LA REVOLUCION

http://www.uci.cu
http://www.facebook.com/universidad.uci
http://www.flickr.com/photos/universidad_uci
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top