I am trying to use python / mechanize to access this web page: http://www.solaradata.com/cgi-bin/mainProgram.cgi
The Javascript function is used in the login form, which generates an MD5 hash from several field values ββbefore sending the results for authentication. Since mechanize cannot execute javascript, I tried to reproduce the same functionality inside python and then present the resulting values. However, I still get the "wrong user / password" errors.
Here is my current code, can someone tell me where I went wrong? Thanks!
url_login = 'http://www.solaradata.com/cgi-bin/mainProgram.cgi' import mechanize import md5 username = 'superfly' #not my real user/pass password = 'stickyguy' #not my real user/pass br = mechanize.Browser() br.open(url_login) br.select_form(nr=0) br.set_all_readonly(False) session = br['session'] br['user'] = username br['password'] = password m1 = md5.new() m1.update(password + username) br['password'] = m1.digest() m2 = md5.new() m2.update(password + session) br['hash'] = m2.digest() for form in br.forms(): #print form request2 = form.click() # mechanize.Request object try: response2 = mechanize.urlopen(request2) except mechanize.HTTPError, response2: pass print response2.geturl() # headers for name, value in response2.info().items(): if name != "date": print "%s: %s" % (name.title(), value) print response2.read() # body response2.close()
source share