Uber API - requests endpoint cannot read read json

℡╲_俬逩灬. 提交于 2019-12-11 00:12:22

问题


I am trying to generate a POST request for the requests endpoint in the following python code:

import requests
...
response = requests.post(
'https://sandbox-api.uber.com/v1/requests',
headers = {
    'Authorization': 'Bearer %s' % access_token,
    'Content-Type': 'application/json'
},
params={"start_latitude":"37.334381","start_longitude":"-121.89432","end_latitude":"37.77703","end_longitude":"-122.419571","product_id":"a1111c8c-c720-46c3-8534-2fcdd730040d"})
data = response.json()

The access_token was obtained using request scope during authorization. The response json is : {"message": "Unable to parse JSON in request body.", "code": "invalid_json"}

Need help in formatting the request properly. Thanks.


回答1:


Figured out the problem - had to replace the params field with a data field and wrap the dict with json.dumps() before sending it off.



来源:https://stackoverflow.com/questions/29752215/uber-api-requests-endpoint-cannot-read-read-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!