Reputation: 195
I'm sending a POST request using urllib with Python.
I used Charles to see the POST that usually gets sent and now i'm trying to send the same thing using urllib.
This is what should be sent according to charles:
{"stuff_values":{"description":"This is description","somestuff":[{"thing":"hello","title":"i love cookies"}]}}
This is what i'm sending:
stuff_values=%7B%27description%27%3A+%27This+is+description%27%2C+%27somestuff%27%3A+%5B%7B%27thing%27%3A+%27hello%27%2C+%27title%27%3A+%27i+love+cookies%27%7D%5D%7D
This is part of my code:
values = {
"stuff_values":{
"description":"this is description",
"somestuff" : [{"thing":"hello",
"title":"i love cookies"}]}
}
data = urllib.parse.urlencode(values)
data = data.encode('ascii')
req = urllib.request.Request(url, data, headers = headers)
Could someone help me figure this out? I'm guessing i have a problem with the encoding part but also with formatting the rest properly.
Thank you for your time!
Upvotes: 0
Views: 36
Reputation: 52039
Try:
data = str(values)
instead. urlencode
is converting certain characters to %xx escapes.
Upvotes: 1