Here is the website's address on which i want to using python/mechanize to auto login:
http://www.autohome.com.cn/tools/hometoplogin.html
And here is my code:
br = Browser()
login_url = 'http://www.autohome.com.cn/tools/hometoplogin.html'
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)
br.open(login_url)
br.select_form(nr = 0)
br['name'] = username
br['pwd'] = password
print br.submit().read()
However the codes throws Http Error 500:
File "build\bdist.win32\egg\mechanize\_mechanize.py", line 541, in submit
File "build\bdist.win32\egg\mechanize\_mechanize.py", line 203, in open
File "build\bdist.win32\egg\mechanize\_mechanize.py", line 255, in _mech_open
mechanize._response.httperror_seek_wrapper: HTTP Error 500: Internal Server Error
sometimes it will throws Http Error 405:
HTTP Error 405: Method Not Allowed
Now i am so confused...please help...
now i have fixed my python code , shown below
username = 'staryin'
password = 'zxy1985'
login_url = 'http://www.autohome.com.cn/tools/hometoplogin.html'
br = Browser()
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)
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.open(login_url)
br.select_form(nr = 0)
br['name'] = username
br['pwd'] = password
br.form.action = login_url
br.submit().read()
it also throws http error 405 shown in below
File "build\bdist.win32\egg\mechanize\_mechanize.py", line 541, in submit
File "build\bdist.win32\egg\mechanize\_mechanize.py", line 203, in open
File "build\bdist.win32\egg\mechanize\_mechanize.py", line 255, in _mech_open
mechanize._response.httperror_seek_wrapper: HTTP Error 405: Method Not Allowed
who can help me to solve this problem?thanks a lot.