Skip to content

Commit

Permalink
fix: add multiple attempts to schwab authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
daneisburgh committed Apr 1, 2024
1 parent 1985c9b commit ade95e2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions invaas/schwab/schwab_api/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async def capture_auth_token(self, route: Route):
self.headers = await route.request.all_headers()
await route.continue_()

async def login(self, username, password):
async def login(self, username, password, attempt=1):
"""This function will log the user into schwab using Playwright and saving
the authentication cookies in the session header.
:type username: str
Expand Down Expand Up @@ -106,7 +106,9 @@ async def login(self, username, password):
# Submit
await self.page.frame(name=login_frame).press('[placeholder="Password"]', "Enter")
await asyncio.sleep(30)
await self.page.wait_for_selector("#_txtSymbol")

if self.page.url != urls.trade_ticket():
raise Exception("Unable to log in to Schwab")
if attempt < 5:
await self.login(username, password, (attempt + 1))
else:
raise Exception("Unable to log in to Schwab")

0 comments on commit ade95e2

Please sign in to comment.