Dimitrius
Dimitrius

Reputation: 786

How to make requests.post not to wrap dict values in arrays in python?

I use python requests.post function to send json queries to my django app.

r = requests.post(EXTERNAL_SERVER_ADDRESS, data={'123':'456', '456':'789'})

But on the external server request.POST object looks like this:

<QueryDict: {'123': ['456'], '456': ['789']}>

Why does it happen? How can I just send a dict?

Upvotes: 0

Views: 453

Answers (2)

Tales P&#225;dua
Tales P&#225;dua

Reputation: 1461

You are sending a dict, Django transform this JSON in this QueryDict objetc automatically when it receives the message. If you want to parse it to an dict, do:

myDict = dict(queryDict.iterlists())

Upvotes: 1

Daniel Roseman
Daniel Roseman

Reputation: 599450

requests is not doing anything here. Presumably your receiving server is Django; that's just how it represents data from a request. request.POST['123'] would still give '456'.

Upvotes: 1

Related Questions