I'm trying use python requests to submit the following form:
<form method="post" action="deliverData.php" enctype="multipart/form-data">
<p><input type="checkbox" name="Description" value="Yes"> Include Course Description
<p><input type="checkbox" name="Extended" value="Yes"> Include Additional Class Meetings
...
<input type="hidden" name="Group" value="Mathematics" />
When I inspect the post request payload in a browser, I get something like the following payload:
------WebKitFormBoundaryNfRaBsIDJ61noG2M
Content-Disposition: form-data; name="Description"
Yes
------WebKitFormBoundaryNfRaBsIDJ61noG2M
Content-Disposition: form-data; name="Extended"
Yes
------WebKitFormBoundaryNfRaBsIDJ61noG2M
...
I successfully receive a response from the server with the following code:
headers = {"Content-Type": "multipart/form-data; boundary=----WebKitFormBoundaryNfRaBsIDJ61noG2M"}
data = ''' <payload from above> '''
response = requests.post(base_url, headers=headers, data=data)
But when I try to use json like:
json1 = {
'Description': 'Yes',
'Extended': 'Yes',
'InstructionMode': 'Yes',
...}
response = requests.post(base_url, headers=headers, data=json1)
There is a server error (Error 500). I can use f'string' to vary the parameters in the payload, but this can't be the correct way to use post requests. What's the proper way to submit this form?