td-ameritrade-python-api icon indicating copy to clipboard operation
td-ameritrade-python-api copied to clipboard

Auth has list index out of range error

Open thenewsupercell opened this issue 4 years ago • 3 comments

first time auth, this happens.

Traceback (most recent call last): File "C:\Users\polym\OneDrive\Desktop\Programming\newtrdaing\main.py", line 12, in <module> TDSession.login() File "C:\Users\polym\OneDrive\Desktop\Programming\newtrdaing\td\client.py", line 266, in login self.oauth() File "C:\Users\polym\OneDrive\Desktop\Programming\newtrdaing\td\client.py", line 387, in oauth self.exchange_code_for_token( File "C:\Users\polym\OneDrive\Desktop\Programming\newtrdaing\td\client.py", line 410, in exchange_code_for_token url_code = list(url_dict.values())[0][0] IndexError: list index out of range

I have no idea how to fix this. I don't understand how i would be out of range of this 0 index list.

i'm trying the sample code. `# Import the client from td.client import TDClient

Create a new session, credentials path is required.

TDSession = TDClient( client_id='', redirect_uri='http://localhost', credentials_path='C:\Users\polym\OneDrive\Desktop\Programming\newtrdaing\td_state.json' )

Login to the session

TDSession.login()

Grab real-time quotes for 'MSFT' (Microsoft)

msft_quotes = TDSession.get_quotes(instruments=['MSFT'])

Grab real-time quotes for 'AMZN' (Amazon) and 'SQ' (Square)

multiple_quotes = TDSession.get_quotes(instruments=['AMZN','SQ'])`

thenewsupercell avatar Jul 22 '21 22:07 thenewsupercell

tried some things, now its like this. {'credential_path': 'C:\\Users\\polym\\OneDrive\\Desktop\\Programming\\newtrdaing\\td_state.json', 'message': 'The credential file does not contain expiration times for your ' 'tokens, please go through the oAuth process.'} Traceback (most recent call last): File "C:\Users\polym\OneDrive\Desktop\Programming\newtrdaing\main.py", line 15, in <module> msft_quotes = TDSession.get_quotes(instruments=['MSFT']) File "C:\Users\polym\AppData\Local\Programs\Python\Python39\lib\site-packages\td\client.py", line 747, in get_quotes return self._make_request(method='get', endpoint=endpoint, params=params) File "C:\Users\polym\AppData\Local\Programs\Python\Python39\lib\site-packages\td\client.py", line 619, in _make_request raise TknExpError(message=response.text) td.exceptions.TknExpError: {"error":"Not Authorized."}

thenewsupercell avatar Jul 22 '21 22:07 thenewsupercell

Yo I had this same issue. Revert the "tried some things now its like this" because whatever you did probably made it worse

But your problem was that you were copying just the refresh token and pasting it in. you should be copying the ENTIRE URL including the localhost part

jamesw3712 avatar Aug 13 '22 08:08 jamesw3712

Yo I had this same issue. Revert the "tried some things now its like this" because whatever you did probably made it worse

But your problem was that you were copying just the refresh token and pasting it in. you should be copying the ENTIRE URL including the localhost part

Same issue, this fixed it. Thanks!

ChristosMaglaras avatar Aug 13 '22 08:08 ChristosMaglaras