Replies: 9 comments 11 replies
-
Quick question, do you actually have a folder in your C Drive that is called |
Beta Was this translation helpful? Give feedback.
-
I do, I also tried creating a blank .json file in that location as well.
…On Sat, Apr 10, 2021 at 9:47 PM Alex Reed ***@***.***> wrote:
Quick question, do you actually have a folder in your C Drive that is
called test? If not that's probably the reason.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#175 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABU436EZ3OBJJMZJSV6NP6LTIEETXANCNFSM42RE7HVA>
.
|
Beta Was this translation helpful? Give feedback.
-
OK I don't know what I'm doing wrong here.
def TestConnect():
TDSession = TDClient(
client_id='ABCDEC',
redirect_uri='http://localhost',
credentials_path='c:\\td_state.json'
)
TDSession.login()
msft_quotes = TDSession.get_quotes(instruments=['MSFT'])
print(msft_quotes)
1. There is no .json file in my root C: drive.
2. I get prompted with a URL to visit when I run the script.
3. I copy the URL out of the command prompt into the browser
4. It prompts me to login and allow the application to access my account.
5. It redirects to my 'localhost' which times out and then I copy the URL
and paste it in the console.
6. I get an error after entering the redirect.
"{'credential_path': 'c:\\td_state.json',
'message': 'The credential file does not contain expiration times for your
'
'tokens, please go through the oAuth process.'}"
There is no exception raised. There is no file located in my root c:
drive. What am I doing wrong?
…On Mon, Apr 12, 2021 at 7:27 PM Alex Reed ***@***.***> wrote:
Yeah you need to delete the blank JSON file or else it will try to load
that and it will fail. I would recommend just have the folder there and
then make sure there is no JSON file inside of it.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#175 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABU436EXIGOVY3UHFM7O5CLTIOFVZANCNFSM42RE7HVA>
.
|
Beta Was this translation helpful? Give feedback.
-
I just got this running last night without too much trouble on Windows 10. I had to change the backslashes to forward slashes for windows. Also I find that running python scripts in Thonny gives me better debug messages than the command line does. Hope this helps. |
Beta Was this translation helpful? Give feedback.
-
OK per @duncanmcdonald I tried forward slashes and again I'm getting the same error. After a few rounds of that, now I get the error: "A third-party application may be attempting to make unauthorized access to your account. For help with your account, contact us. For information on securing your account, visit the TD Ameritrade Security page." When I paste the URL for the setup into the browser. What happened? I literally cannot figure out why this will not create a .json file but it never happens. I have tried the path to the root c:\ drive with:
None of these create a .json file on my c: drive. |
Beta Was this translation helpful? Give feedback.
-
I'm thinking that you have a permissions issue when the code tries to create the JSON file so it doesn't get created. That in turn gives rise to the "'The credential file does not contain expiration times..." error message since the file does not exist. Here is the exact code I am using (note I put the client_id in an environment variable):
|
Beta Was this translation helpful? Give feedback.
-
Edit I tried Thonny and the exact same script worked fine. I was using PyScrtipter 4.0. Maybe that is the issue? Thonny is just so basic, no var type ahead, no var explorer. Unless i am missing something. I am having the same issue. No file is created but no error. Then the message {'credential_path': 'C:\temp\td_state.json', I tried all kinds of path locations, used r in front changed the slashes, etc. I actually write Python code for a living so I thought I could get it. Thanks for any insight. `# Import the client Create a new session, credentials path is required.TDSession = TDClient( Login to the sessionTDSession.login() Grab real-time quotes for 'MSFT' (Microsoft)msft_quotes = TDSession.get_quotes(instruments=['MSFT'])' |
Beta Was this translation helpful? Give feedback.
-
It's not a permissions issue. I write python code that writes to these
directories all the time. It makes no sense and the fact that someone else
is having the same problem finally validates that I'm not crazy.
…On Thu, May 6, 2021 at 12:59 AM duncanmcdonald ***@***.***> wrote:
I'm thinking that you have a permissions issue when the code tries to
create the JSON file so it doesn't get created. That in turn gives rise to
the "'The credential file does not contain expiration times..." error
message since the file does not exist. Here is the exact code I am using
(note I put the client_id in an environment variable):
Import the client
from td.client import TDClient
import json
import os
Create a new session, credentials path is required.
TDSession = TDClient(
client_id = os.environ['TDAMERITRADE_CLIENT_ID'],
redirect_uri = 'http://localhost',
credentials_path='C:/Users/dmcdo/Documents/Trading/td-ameritrade-python-api-0.3.5/samples/credentials.json'
)
Login to the session
TDSession.login()
Grab real-time quotes for 'MSFT' (Microsoft)
msft_quotes = TDSession.get_quotes(instruments=['MSFT'])
Iterate over key/value pairs in dict and print them
for p_id, p_info in msft_quotes.items():
print("\nTicker:", p_id)
for key in p_info:
print(key + ':', p_info[key])
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#175 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABU436HOHJBZ44O5OQYWE23TMIV4VANCNFSM42RE7HVA>
.
|
Beta Was this translation helpful? Give feedback.
-
I got this to work, but had to use a Jupyter labs notebook(Started server and ran code in browser). Running it through VS Code never worked. |
Beta Was this translation helpful? Give feedback.
-
Hi all:
I'm just getting started and I'm having trouble with the credentials file. I'm specifying a path but no file gets created at the path I specify. Am I supposed to create the JSON file myself first? How does this work? I've tried single backslashes, double backslashes, and forward slashes and nothing seems to create the file. I do get the challenge/response from TD Amitrade but nothing involving the credentials gets saved and my next line to request quotes fails with a credentials path error.
Beta Was this translation helpful? Give feedback.
All reactions