I am trying to send a POST request (in Python) to a server that is expecting an array containing JSON. I can't seem to format the data properly. How can I format the following payload to behave like a JavaScript array for a Node.js server?
POST /api/adduser/
Node.js expected Payload:
[
{'user':'jon','email':'[email protected]'},
{'user':'jon2','email':'[email protected]'}
]
My current code:
import requests
import json
payload = \
[
{
'user': 'hello',
'email': '[email protected]'
},
{
'user': 'helloAgain',
'email': '[email protected]'
}
]
res = requests.post('http://localhost/api/users', data=json.dumps(payload))
#res -> 400 error -> reason: "wrong json format - must be an array"