How do I check whether the submit has been successful or not. When I give correct username it does not show anything. But even if I submit wrong username, it does not throw any errors. How to catch the errors or check success results. Any help will be greatly appreciated. Thank you.
code:
try:
import mechanize
except ImportError:
print "Could not import Mechanize. Please install from Mechanize website."
br = mechanize.Browser()
interletter = 'http://somesite.com/adminpanel/index.php'
br.open(interletter)
print br.geturl()
br.select_form(name="frm_login")
br["admin_userid"] = "user"
br["admin_password"] = "pword"
result2 = br.submit()
http://somesite.com/adminpanel/index.php
<response_seek_wrapper at 0x25a3cb0 whose wrapped object = <closeable_response at 0x25ab738 whose fp = <socket._fileobject object at 0x025A0970>>>
It's possible that the web server you're dealing with is still sending an HTTP 200 status code, even if your login fails. They may just be including error text in the body of the response.
You should be able to call result2.read() to get the contents of the response object. Then, you'll have to examine or parse that to determine whether your login attempt was successful or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With