Here is my code: from robobrowser import browser
url = 'http://diesel.elcat.kg/index.php?act=Login&CODE=00'
url3 = 'http://diesel.elcat.kg/index.php?act=post&do=reply_post&f=178&t=233500064'
m = browser.RoboBrowser()
m.open(url)
# SIGNING IN(form1)
form1 = m.get_form(action='https://diesel.elcat.kg/index.php?act=Login&CODE=01')
form1['UserName'].value = 'Username'
form1['PassWord'].value = 'Password'
m.submit_form(form1)
# FINISHED SIGNING IN(everything worked)
# GOING TO THE PAGE WHERE FORM IS LOCATED
m.open(url3)
# Can't submit this form
form2 = m.get_form(action="http://diesel.elcat.kg/index.php?")
form2['Post'].value = 'up'
m.submit_form(form2)
I can sign in to the website so form1 works, but when I try in this case leave a comment(up), form2 does not work.I am keep getting either InvalidSubmit error either Bad Request error. Code of form1 and code of form2 seem to be the same, but one works and another does not. I am using python3.5 and robobrowser, and I am using Mac OS if that's gonna help. Thank you in advance. Here is my traceback:
Traceback (most recent call last):
File "/Users/bkkadmin/Desktop/Daniiar/upper/test2.py", line 18, in <module>
m.submit_form(form)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/robobrowser-0.5.3-py3.5.egg/robobrowser/browser.py", line 339, in submit_form
payload = form.serialize(submit=submit)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/robobrowser-0.5.3-py3.5.egg/robobrowser/forms/form.py", line 226, in serialize
include_fields = prepare_fields(self.fields, self.submit_fields, submit)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/robobrowser-0.5.3-py3.5.egg/robobrowser/forms/form.py", line 154, in prepare_fields
raise exceptions.InvalidSubmitError()
robobrowser.exceptions.InvalidSubmitError
I experienced the same issue today, with the same exact errors. One possible cause of the above issue is that your form2 actually contains more than one submit field, corresponding to more than one submit button in the original html. You can check this by print(len(list(form2.submit_fields.items(multi=True))))
. If this is the case, your call to submit_form
has to be modified as m.submit_form(form2, submit=your_submit)
, where the second argument your_submit
is the relevant submit field you want to use. This reference discusses how to extract the submit field you desire.
Incidentally, if you wonder where the long print
code comes from, it comes from the body of prepare_fields
in robobrowser/forms/form.py, which is indicated in one of the error outputs you posted.
Hope this helps!
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