Mechanize not logging in to site properly
Question: After spending the best part of 3 hours getting nowhere, i thought i would ask
a question myself. i am using python and `mechanize`'s `Browser`. I am trying
to login to my home router. i can get to the login page, fill the password
field (eg `br.form['password'] = 'mypassword'` etc), but now i am stuck
because no matter what i try, i always get sent to a page saying i am
forbidden/session has timed out i am handling cookies with a cookie jar, i
have handled robots, but it still doesnt love me enough to let me login....
help? if you have any suggestions as to why i can not login successfully,
please, please, please share xxx

**EDIT:**

it does have javascript, but i am simulating it

    
    
    **EDIT2:**
    

i just realized that the javascript i am simulating is for pressing the
disconnect button on the previous page...... probably fix my problem if i
emulate the javascript for this page ......

i am faking the user agent

i will have a look w/ wireshark xxx

ps thanks for replying so fast xx

UPDATE: sigh. i think it may just be one of those things where you just have
to say f it and move on because i am emulating the javascript it needed
exactly as it is done (just checking, MD5 ==
hashlib.md5("...").hexdigest()?).... thanks anyway people xxx


Answer: Here's some sample code for mechanize implementing cookies and a fake user-
agent -- might help out...

    
    
    import mechanize
    
    cookies = mechanize.CookieJar()
    opener = mechanize.build_opener(mechanize.HTTPCookieProcessor(cookies))
    opener.addheaders = [("User-agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6; en-us) AppleWebKit/533.4 (KHTML, like Gecko) Version/4.1 Safari/533.4"),]
    mechanize.install_opener(opener)
    
    url = "http://your_home_router_address"
    content = mechanize.urlopen(url)
    return content.read()
    

