Skip to content
Advertisement

How to send raw data in a POST request Python

Body I’m trying to send:

update_request={
        "id": "f07de0a44c2911ea8fb2bc764e10b970",
        "user": {
            "user": "3491574055045",
            "timestamp": "1640049459",
            "signature": "YQvl1dWkN6MrHQ8xGwEQndVo2QdPSzc6EqLJslzNjy4%3D",
            "code": "test"
        }
    }

This is my code right now:

url = "https://api.ordergroove.com/customer/update_customer"

headers = {
    'content-type': 'application/json'
}

body = """
    update_request={{
         "id": "f07de0a44c2911ea8fb2bc764e10b970",
         "user": {
             "timestamp": "1640049459",
             "signature": "YQvl1dWkN6MrHQ8xGwEQndVo2QdPSzc6EqLJslzNjy4%3D",
             "code": "test"
         }
     }}
"""

#Send and print response
response = requests.post(url, data=body, headers=headers)

If I run this in Postman though it works just fine: Postman screenshot

Advertisement

Answer

import requests

url = "https://46463d29-e52d-4bb9-bdda-68f0dfd7d06d.mock.pstmn.io/test"

payload = " update_request={{rn         "id": "f07de0a44c2911ea8fb2bc764e10b970",rn         "user": {rn             "timestamp": "1640049459",rn             "signature": "YQvl1dWkN6MrHQ8xGwEQndVo2QdPSzc6EqLJslzNjy4%3D",rn             "code": "test"rn         }rn     }}"
headers = {
  'Content-Type': 'text/plain'
}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)

you can geenrate the code form postman itself

enter image description here

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement