Can python mechanize handle HTTP auth?
Question: Mechanize (Python) is failing with 401 for me to open http digest URLs. I
googled and tried debugging but no success.

My code looks like this.

    
    
    import mechanize
    
    project = "test"
    baseurl = "http://trac.somewhere.net"
    loginurl = "%s/%s/login" % (baseurl, project)
    b = mechanize.Browser()
    b.add_password(baseurl, "user", "secret", "some Realm")
    b.open(loginurl)
    


Answer: Mechanize claims that the parameters should be uri, username and password as
parameters, but you have four parameters. Four parameters are correct for
urllib2.add_password, but then the first parameter should be the realm, not
the uri.

<http://wwwsearch.sourceforge.net/mechanize/>

I'd try to change that first.

Does trac require digest? if not a next step could be to try using basic auth,
as a test to see if that works, since you can add that with just addHeader:

    
    
    import base64
    from mechanize import Browser
    browser = Browser()
    browser.addheaders.append(('Authorization', 'Basic %s' % base64.encodestring('%s:%s' % (user, pwd))))
    

