I am trying to pass the json object to one of my URLs which accepts the JSON data.
The below works:
payload='{"message": "hello"}'
headers = {'content-type': 'application/json', 'Accept-Charset': 'UTF-8'}
r = requests.post(url, data=payload, headers=headers)
r.text is giving me "hello"
But when I tried to pass the variable
s="hello"
payload='{"message":' +str(s)+ '}'
headers = {'content-type': 'application/json', 'Accept-Charset': 'UTF-8'}
r = requests.post(url, data=payload, headers=headers)
The above didnt work. When I tried to load as a JSON, it is throwing me error as well
payload=json.loads(payload)
JSONDecodeError: Expecting value: line 1 column 12 (char 11)
Also I wanted to pass b'blahblah' as a JSON message. Since passing a string didnt work for me, I didnt attempt to pass bytes format.
Please advice