Sherry Sherry - 9 months ago 94
Python Question

Python requests to fill form

I am using python requests to fill the form.

payload = {"name": 'TEST', 'XXXX': '12345' ,'YYYY':'EEEE','ZZZZ':''}"", data=payload, auth=HTTPBasicAuth('username', 'password'),verify=False)

Its not submitting the form, the form has two buttons SAVE and CANCEL.

In my payload I havn't included anything related to the buttons, as what I know is that submission of form is handled by post method.

following is the HTML code for that part

<div id="button_row_12" class="button_row form_pane">
<input type="submit" name="_form_action1" value="Save" class="button" onClick="this.form._form_action1.disabled=true;this.form._form_action.value='Save';this.form.submit();">

<input type="button" name="_form_action2" value="Cancel" class="button" onClick="this.form._form_action2.disabled=true;this.form._form_action.value='Cancel';this.form.submit();">
<input type="hidden" name="edit" value="0">
<input type="hidden" name="type" value="iscan">
<input type="hidden" name="_form_visited" value="1">
<input type="hidden" name="_form_action" value="">

Answer Source

You should also add the _form_action field to your payload to imitate the Javascript onClick event:

payload = {"name": 'TEST', 'XXXX': '12345' ,'YYYY':'EEEE','ZZZZ':'', '_form_action': 'Save'}