1
votes

I am facing and issue while requesting a cab through Uber Api with Python. These are the steps I have followed :

  1. Creating a session with my server_token.
  2. Authorizing with my credentials.
  3. Got authorization_url and user authentication is done.
  4. Created an object with a session I got from user authentication.
  5. Got the credentials using the method :

    credentials = new_session.oauth2credential

  6. Estimation for the ride :

    estimate = client.estimate_ride(product_id=PRODUCT_ID, start_latitude=xx.xxx, start_longitude=xx.xxx, end_latitude=xx.xxx, end_longitude=xx.xxx)

  7. Fetching fare Amount :

    fare = estimate.json.get('fare')

  8. I try to request a ride with below code and get the exception :

    response = client.request_ride(product_id=Product_ID, start_latitude=xx.xxx, start_longitude=xx.xxx, end_latitude=xx.xxx, end_longitude=xx.xxx, fare_id=fare.get('fare_id'))

  9. Exception :

    ClientError: 401: This endpoint requires at least one of the following scopes: request.delegate.tos_accept, request, request.delegate

Please let me know where am I going wrong. Did I miss any step ?

Thanks in advance.

1

1 Answers

3
votes

The issue is you need to add the 'request' privileged scope when creating the token.

from uber_rides.auth import AuthorizationCodeGrant
auth_flow = AuthorizationCodeGrant(
    <CLIENT_ID>,
    <SCOPES>,
    <CLIENT_SECRET>,
    <REDIRECT_URI>
)
auth_url = auth_flow.get_authorization_url()

See more details in the python ride requests tutorial.