I want to use mechanization to enter the page and get some information. But nonetheless, I'm trying to authenticate. It just fails with the HTTP error code 401 , as you can see below:
r = br.open('http://intra')
File "bui...e\_mechanize.py", line 203, in open
File "bui...g\mechanize\_mechanize.py", line 255,
in _mech_openmechanize._response.httperror_seek_wrapper: HTTP Error 401: Unauthorized
This is my code:
import mechanize
import cookielib
br = mechanize.Browser()
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)
br.set_handle_equiv(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
br.add_password('http://intra', 'myusername', 'mypassword')
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]
r = br.open('http://intra')
html = r.read()
print html
What am I doing wrong? visit http://intra(internal page), for example. chrome, it opens windows and asks for username / password once, and then everything is fine.
The dialog that pops up looks like this:

source
share