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

Issues with refreshing credentials #16

Open
avih7531 opened this issue Mar 4, 2025 · 3 comments
Open

Issues with refreshing credentials #16

avih7531 opened this issue Mar 4, 2025 · 3 comments

Comments

@avih7531
Copy link

avih7531 commented Mar 4, 2025

I'm encountering an error where I can't run my script more than a few times before I get

{"code":null,"header":null,"message":"Invalid credentials.","payload":null}
An error occurred: Login failed, check credentials

I assume there needs to be some kind of credentials refresh so I ran refresh = public.refresh_token() and I get this error:
An error occurred: Portfolio request failed: {"timestamp":"2025-03-04T17:39:03.391+00:00","status":403,"error":"Forbidden","path":"/hstier1service/account/xxx/portfolio"}

Script snippet:

public = Public()
    public.login(
        username="xxx",
        password="xxx",
        wait_for_2fa=True,
    )

    refresh = public.refresh_token()
    positions = public.get_positions() # totally works if the above line is removed but returns an error after a few runs
@NelsonDane
Copy link
Owner

Hello, I've investigated this and I think I found and fixed the issue!

Basically, I added auto token refresh for when access token expires (every 15 minutes). That should make it that you only need to login once and then it will just work without you needing to refresh manually. I also found that Public changes the accountUUID on refresh, which is why you got the error 403. I've also fixed that so when we refresh our token it gets the updated accountUUID.

Please update to 1.2.2 and see if that fixes it for you!

@avih7531
Copy link
Author

@NelsonDane Amazing thank you! It totally works, but I'm noticing I'm asked for a 2FA code about every 15 minutes after initial login. Any insight? Thank you!

@NelsonDane NelsonDane reopened this Mar 12, 2025
@NelsonDane
Copy link
Owner

@NelsonDane Amazing thank you! It totally works, but I'm noticing I'm asked for a 2FA code about every 15 minutes after initial login. Any insight? Thank you!

Awesome, glad it's starting to work! I'm not sure if this will solve your issue, but I noticed that when logging in it would always do 2FA, regardless if we have valid cookies saved from a previous session. I just pushed 1.2.3 that checks for saved cookies first before doing a full login. Let me know how it goes!

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

2 participants