I'm trying to connect a web page with mechanize but I'm getting a http 401 error.
Here's my code;
import base64, mechanize
url = "http://www.dogus.edu.tr/dusor/FrmMain.aspx"
user = "user"
pwd = "pwd"
br = mechanize.Browser()
br.set_handle_robots(False)
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
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')]
br.add_password(url, user, pwd)
#br.addheaders.append(('Authorization', 'Basic %s' % base64.encodestring('%s:%s' % (user, pwd))))
print br.open(url).read()
Both add_password
and addheaders
are not working. Is it because I never specified a realm? How can I get what realm is that web page using? The username and password that I'm using are correct, as I can login using chrome with those credentials.