HTTP PUT request in Python using JSON data
Your data
is already a JSON-formatted string. You can pass it directly to requests.put
instead of converting it with json.dumps
again.
Change:
response = requests.put(url, data=json.dumps(data), headers=headers)
to:
response = requests.put(url, data=data, headers=headers)
Alternatively, your data
can store a data structure instead, so that json.dumps
can convert it to JSON.
Change:
data = '[{"$key": 8},{"$key": 7}]'
to:
data = [{"$key": 8},{"$key": 7}]