Uber API - requests endpoint cannot read read json

2019-07-21 04:39发布

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条回答
太酷不给撩
2楼-- · 2019-07-21 05:36

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.

查看更多
登录 后发表回答