pythonpostput400-bad-request

Put/Post errors while trying to access it from through python. "Bad Request. The JSON payload should be inside a root property called


I am trying to post/put to Sheety via Python:

SHEETY_URL = "https://api.sheety.co/gfhgfhjfdghjgfjf/flightDeals/prices/5"

header = {
    "Content-Type" : "application/json"
}
params_sheety = {
    "price": {
        "iataCode": "PLN"
    }
}
response_sheety = requests.put(url=SHEETY_URL, params=params_sheety, headers=header)
print(response_sheety)
print(response_sheety.json())

=======================================================

Getting Bad request Error:

<Response [400]> {'errors': [{'detail': "Bad Request. The JSON payload should be inside a root property called 'price'. Check https://sheety.co/docs for more details."}]}

The same request works fine with Postman.

Postman


Solution

  • When you use params=params_sheety, the parameters are not sent as json.

    Use json=params_sheety to send them as json.

    This also sets the content-type header to json automatically, so you don't need headers=header.