In my current program, I am accessing an HTTP authenticated page like this one that works fine:
import urllib2
url = 'http://test.localdomain/test.pl'
realm = 'Test DB'
username = 'foo'
password = 'bar'
auth_handler = urllib2.HTTPBasicAuthHandler()
auth_handler.add_password(realm, uri , username, password)
opener = urllib2.build_opener(auth_handler)
data = opener.open(url).read()
Now I want to click the button on this page after logging in. I found a mechanics library for Python that can easily do such things. Unfortunately, I was not able to successfully complete the same basic authentication as above when using mechanize. This is what I tried:
from mechanize import Browser
url = 'http://test.localdomain/test.pl'
realm = 'Test DB'
username = 'foo'
password = 'bar'
browser = Browser()
browser.add_password(url, username, password, realm)
browser.open(url)
But then I get the following exception:
HTTP Error refresh: The HTTP server returned a redirect error that would lead to an
infinite loop.
The last 30x error message was:
OK
How can i fix this? Or can I let the mechanization use the already existing authhander created by urllib2 in my first fragment?
source
share