timkpaine / tdameritrade

Python interface to TD Ameritrade (https://developer.tdameritrade.com)
Apache License 2.0
520 stars 202 forks source link

Error authenticating the first time #136

Closed shahab-cl closed 3 years ago

shahab-cl commented 3 years ago

Describe the bug A clear and concise description of what the bug is.

When trying to authenticate for the first time. I run the command below and it opens chrome with a page which is not the authentication page. Plese see attachement. I login and then hit enter.

Screen Shot 2021-04-20 at 6 53 57 PM

Running python in command line with the following command

Python 3.9.2 (default, Mar 15 2021, 17:27:56) [Clang 12.0.0 (clang-1200.0.32.29)] on darwin Type "help", "copyright", "credits" or "license" for more information.

import tdameritrade tdameritrade.auth.authentication ('xxxxx', "http://localhost/") after giving access, hit enter to continue Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.9/site-packages/tdameritrade/auth/init.py", line 65, in authentication code = up.unquote(driver.current_url.split('code=')[1]) IndexError: list index out of range

To Reproduce Device Mac.

timkpaine commented 3 years ago

This happens when one of your provided fields (e.g. redirect_uri) doesn't match its configuration, for example if you tell td https://localhost but provide http://localhost. Make sure all your fields match.

shahab-cl commented 3 years ago

Got it. That worked. I am wondering if there is a way to do this inside a python file instead of running this from command line. e.g. here is the syntax.

  1. Check if the the access token is not present, then call td.auth.authentication ()
  2. save the contents from the output into a json file .
  3. use this file for the next td.TDClient

I couldnt find a way to run this from the file as the function dosent wait for the browser.