I am trying to POST Boxes = [{'X': 2423, 'Y': 532, 'W': 7456, 'H': 2345}]
to the DRF server, I receive status code 200, However, on the server, I receive weird format: "Boxes": "[{\"X\": 1028, \"Y\": 228, \"W\": 711, \"H\": 852}]"
.
I don't understand where the '/' comes from.
Here is the POST request in python:
Boxes = [{"X": 2423, "Y": 532, "W": 7456, "H": 2345}]
url = "http://art1x.pythonanywhere.com/snippets/1/"
username = "artemii"
password = "admin"
data = {"Boxes": json.dumps(Boxes)}
response = requests.put(url, auth=(username, password), data=data)
print(response.status_code)
'Boxes' is a list
Please help! Any suggestion is valuable
CodePudding user response:
The weird format looks like escape characters. Setting content type should fix this i think.
e.g:
headers["Content-Type"]="application/x-www-form-urlencoded"
link to post explaining Content type
CodePudding user response:
Remove json.dumps
if you want to send Boxes as json object instead of a string:
data = {"Boxes": Boxes}
json.dumps(Boxes)
convert Boxes into a string. requests.put
then convert data into string for transport, where it inserts escape characters because the content is a string.