Closed WinesProof closed 8 months ago
Thanks for the investigation and work here! I'll be ready to revert if anyone reports regression, but this LGTM!
Thanks, It looks great to me as well. I will try this when I have time
I have below exception triggered and hence noticed the row 350 missed a "f"
it can be updated to
raise ValueError(f"Error updating Bearer token: {r.reason}")
everything else so far so good. Thanks.
Good catch. See #39
But if you got that exception, it means something went wrong when attempting to update the token, so we'll eventually want to track that down. The fix for that error message will hopefully help reveal what that is.
Thanks for your update.
Sorry if I have said this twice. The update_token used elsewhere sometimes will also trigger exception. My current work-around is to catch this exception and use another login() to bypass. Doing this at least on my side is stable/reliable for a while loop to fetch data all day long. Call update_token more than once at the same place as what itsjafer has tried (in the commented code) doesn't work on my test too.
Ah, yes, if you're trying to keep something running for a long time that doesn't surprise me. How long does it usually take to get that error?
I update the market data every 5 minutes, I think it just expired due to no-activity.
Using this code, it looks like it logs out after an hour regardless of activity (or at least I haven't tried whatever activity might keep it logged in). Using a browser, it logs out after an hour unless you click on a link or refresh the page. Perhaps there's some way to spoof (ideally without playwright) whatever happens when clicking/refreshing.
I am satisfied with what we have right now. The other platform API is more difficult to use and need regularly human interaction due to security concern. The schwab API is the most convenient so far. Just catch the exception and re-login seems so easy from my point of view.
When using a web browser, v2 requests (all the ausgateway.schwab.com urls) do not include cookies and use at least two different bearer tokens depending on the endpoint. This updates the v2 requests to match that.