Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Uber API, UberIllegalState(error_message)
#1
Hello, I am trying to create a database with the Uber api that tracks my trip history.

#! python3
import openpyxl, os, pprint, requests

from uber_rides.session import Session
from uber_rides.client import UberRidesClient


from uber_rides.auth import AuthorizationCodeGrant


auth_flow = AuthorizationCodeGrant(
    'client_id=CLIENT_ID', 
    scopes='history_lite',
    client_secret='CLIENT_SECRET',
    redirect_url='?code=XXXXXXX'
)
auth_url = auth_flow.get_authorization_url()

#print(auth_url)

session = auth_flow.get_session('https://localhost/?code=XXXXXXXXXX')


client = UberRidesClient(session, sandbox_mode=True)
credentials = session.oauth2credential

response = client.get_driver_profile()
profile = response.json

first_name = profile.get('first_name')
last_name = profile.get('last_name')
email = profile.get('email')

response = client.get_driver_trips()
trips = response.json

print(trips)
print (first_name)
When I run my code I get an illegal state CSRF error

Traceback (most recent call last):
  line 21, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/uber_rides/auth.py", line 294, in get_session
    authorization_code = self._verify_query(query_params)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/uber_rides/auth.py", line 255, in _verify_query
    raise UberIllegalState(error_message)

uber_rides.errors.UberIllegalState: CSRF Error. Expected YYYY, got XXXX
From what I've gathered so far the error is coming up because every time the code is ran a new authorization url is requested and the original that is hard-coded doesn't match the newly requested auth code in the redirect_uri.

I am hoping someone would be able to help me get around this error, and somehow automate the auth so they match.
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)