python - 优步 API : request_ride with sandbox_mode=True is throwing error message

标签 python uber-api

request_ridesandbox_mode=True 抛出错误消息。下面是我的代码和完整的错误消息。

#Python 3.x
from uber_rides.session import Session
from uber_rides.client import UberRidesClient
session = Session(server_token="something-special")
client = UberRidesClient(session,sandbox_mode=True)
#UberX product id
product_id = '04a497f5-380d-47f2-bf1b-ad4cfdcb51f2' 
response = client.request_ride(product_id, 37.77, -122.41, 37.79, -122.41)
ride_details = response.json
ride_id = ride_details.get('request_id')
response = client.update_sandbox_ride(ride_id, 'accepted')
print(response)

#error message
...
...
uber_rides.errors.ClientError: The request contains bad syntax or   
cannot be filled due to a fault from the client sending the request.

最佳答案

您收到 4XX ClientError,因为您尝试使用服务器 token 请求乘车。如果您处理该错误并检查它,您会发现它是 401:未经授权的错误

为了请求乘车,您需要获取具有 request 范围的 OAuth2 访问 token 。

服务器 token 可以访问产品、时间估计和价格估计等端点。要访问更 protected 资源(例如用户事件或请求端点),您需要遵循 OAuth2 get an access token .

还有一个OAuth2 Authorization example在 Uber 的 Python SDK 中。

关于python - 优步 API : request_ride with sandbox_mode=True is throwing error message,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34181363/

相关文章:

python - 正确终止在线程中运行的 Flask Web 应用程序

python - 如何使用 pandas 在 Excel 工作表中的同一个图形上绘制多个数据框?

适用于 Uber API 的 Android oAuth - SSO 因 INVALID_APP_SIGNATURE 挂起

python - 与日期的日期时间差 0 秒

python - 合并日期和时间;值错误 : hour must be in 0. .23

iOS/Uber 集成 : link_text and partner_deeplink not working in testing

ios - 优步 iOS SDK - 401 错误

java - Uber API 未经授权访问问题

ios - 在 iOS 上使用第 3 方应用程序打开 Uber 应用程序然后返回到第 3 方应用程序的可能性

python - 如何在 Python 中分割输入参数