Reputation: 55
I'm trying to call an API that wants a list of dicts for one value. I build a dict that looks similar to this:
dataset = {
'name': 'somename',
'note': 'somenote',
'extras': [{'first': 'entry'}]
}
I'm including this in my POST:
r = requests.post("URL_ENDPOINT", data=dataset, headers=headers)
Checking the actual dataset
dictionary shows the list of dicts correctly.
{'name': 'somename', 'note': 'somenote', 'extras': [{'spatial': 'test'}]}
But checking the requests object, r.text
:
... "extras": "first", "type": "dataset"}}, ...
It looks like the list of dicts is being munged in some fashion?
Upvotes: 1
Views: 320
Reputation: 55
I’m less than smart - the API wanted the dict to use “key”: and “value”:
I did try a JSOn package and it looks like it would work also. Thank you very much!
Upvotes: 0
Reputation: 16187
Try to inject json
parameter instead of data
r = requests.post("URL_ENDPOINT", json=dataset, headers=headers)
Upvotes: 0