Posting a complex data dictionary with a python request

I am sending data using a mail request.

info={'abc':123, 'xyz':454, 'list':[{'test':33},{'test':44}]} request.post(url,data=info) 

When I posted the above data, then it looks like in api

  <QueryDict: {u'abc': [u'123'], u'xyz': [u'454'], u'list': [u'test', u'test']}> 

but I want my data to be in the format below.

  <QueryDict: {u'abc': [u'123'], u'xyz': [u'454'], u'list': [u"[{'test':'33'},{'test':'44'}]"]}> 

How should I achieve the above format.

+4
source share
1 answer

Convert each dict value to a string (from a @falsetru comment edited according to the brackets):

 request.post(url, data={key: str(value) for key, value in info.items()}) 
0
source

Source: https://habr.com/ru/post/1490728/


All Articles