简体   繁体   中英

How do I properly recreate POST request in Python

Im pretty new to Python Requests so bear with me. Im trying to POST a requests with the following data

data = {
"form_uuid": "taGE9xyeDAYWQw_MyeQvIw",
"formResponse": {"First Name (As per IC/ID)": "nancy",
             "Last Name (As per IC/ID)":"thomas",
             "E-mail":"nancythomas998@gmail.com",
             "Size Selection (US)":"8.5"},
"confirmationMail": "nancythomas998@gmail.com",
"is_pro": "true"
}

enter_raffle = requests.post(URL,data=data)

However, because of the dictionary within the dictionary itself, I cant seem to properly recreate the request. If it helps, this is what the form data looks like on the chrome.network panel formdata

I observed that the request headers' content type was "application/x-www-form-urlencoded" too if that helps

The formResponse value appears to be JSON. You could try

import json


response = {
    "First Name (As per IC/ID)": "nancy",
    "Last Name (As per IC/ID)":"thomas",
    "E-mail":"nancythomas998@gmail.com",
    "Size Selection (US)":"8.5"
}

data = {
    "form_uuid": "taGE9xyeDAYWQw_MyeQvIw",
    "formResponse": json.dumps(response),
    "confirmationMail": "nancythomas998@gmail.com",
    "is_pro": "true"
}

enter_raffle = requests.post(URL,data=data)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM