Using Python 3.5 and requests 2.18.4 I need to send data to another service, and it is currently failing for some reason. Sending is made after I receive and clean data from another service, and eventually get the data verified and set as a native python dict. This works when the data is hardcoded and I am not using the incoming data (hardcoded json string):
def my_post_method(self, url, data):
# import requests (above)
return requests.post(
url,
data='{"keyA":"valA", "keyB":"valB" ... }',
headers={'Content-Type': 'application/json'},
) # status 200
But I cannot send it with the original data for some reason.
def my_post_method(self, url, data):
# import requests, json (above)
d = json.dumps(data)
return requests.post(
url,
data=d,
headers={'Content-Type': 'application/json'},
) # status 400
d from above: {"keyA":"valA", "keyB":"valB" ... }
I tried to use the requests json parameter instead of data, but the other service is apparently expecting data parameter on the other end. Does it mean that the service I am posting to is waiting on a json-formatted string?