mosquito242
mosquito242

Reputation: 353

Python Requests Library not encoding dictionary payload properly for post request

So I'm working on a python script that uses the requests library to make a post request after gathering some data from some web API's.

At the end, I have a dictionary that looks something like

my_data = {"link": "value", "name": "value", "last_event": "value", people: []}

Whenever I run the following code to make a request:

post_r = requests.post("http://127.0.0.1:3000/companies", data=my_data)

I find that the server receives the value of data to only be equal to the string "last_event", ignoring everything else.

Does anybody have any idea why this would happen?

(If it matters, the server the code is hitting is a rails server).

Upvotes: 1

Views: 1334

Answers (1)

mosquito242
mosquito242

Reputation: 353

Solved it - because i was using a nested dictionary, it worked when I used json=my_data.

Upvotes: 5

Related Questions