Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auth has list index out of range error #201

Open
thenewsupercell opened this issue Jul 22, 2021 · 3 comments
Open

Auth has list index out of range error #201

thenewsupercell opened this issue Jul 22, 2021 · 3 comments

Comments

@thenewsupercell
Copy link

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
Copy link
Author

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."}

@jamesw3712
Copy link

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

@ChristosMaglaras
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants