Sherry Sherry - 1 month ago 23
Python Question

Python requests to fill form

I am using python requests to fill the form.

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

x=requests.post("https://example.com", 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();">
</div>
<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="">
</form>

Answer

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'}
Comments