Sending List Of Dicts As Value Of Dict With Requests.post Going Wrong
I have clien-server app. I localized trouble and there logic of this: Client: # -*- coding: utf-8 -*- import requests def fixing: response = requests.post('http://url_for_aut
Solution 1:
Looks like request (because it have x-www-encoded-form default) cant include list of dicts as value for key in dict so... I should use json in this case. Finally I maked this func:
import requests
import json
deffixing:
response = requests.post('http://url_for_auth/', data={'client_id': 'client_id',
'client_secret':'its_secret', 'grant_type': 'password',
'username': 'user', 'password': 'password'})
f = response.json()
headers = {'authorization': f['token_type'].encode('utf-8')+' '+f['access_token'].encode('utf-8'),
'Content-Type': 'application/json'}
data = {'coordinate_x': 12.3, 'coordinate_y': 8.4, 'address': u'\u041c, 12',
'products': [{'count': 1, 'id': 's123'},{'count': 2, 'id': 's124'}]}
response = requests.post('http://url_for_working/', data=json.dumps(data),
headers=headers)
response.text
There I got right response. Solved!
Post a Comment for "Sending List Of Dicts As Value Of Dict With Requests.post Going Wrong"