Skip to content

Commit

Permalink
fix otp code
Browse files Browse the repository at this point in the history
  • Loading branch information
vladkens committed Apr 18, 2024
1 parent 264ca7a commit 9fa6343
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion twscrape/accounts_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async def add_account(
user_agent: str | None = None,
proxy: str | None = None,
cookies: str | None = None,
mfa_code: str | None = None
mfa_code: str | None = None,
):
qs = "SELECT * FROM accounts WHERE username = :username"
rs = await fetchone(self._db_file, qs, {"username": username})
Expand Down
7 changes: 5 additions & 2 deletions twscrape/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from dataclasses import dataclass
from datetime import timedelta
from typing import Any
import pyotp

import pyotp
from httpx import AsyncClient, Response

from .account import Account
Expand Down Expand Up @@ -121,6 +121,9 @@ async def login_enter_password(ctx: TaskCtx) -> Response:


async def login_two_factor_auth_challenge(ctx: TaskCtx) -> Response:
if ctx.acc.mfa_code is None:
raise ValueError("MFA code is required")

totp = pyotp.TOTP(ctx.acc.mfa_code)
payload = {
"flow_token": ctx.prev["flow_token"],
Expand All @@ -133,7 +136,7 @@ async def login_two_factor_auth_challenge(ctx: TaskCtx) -> Response:
}

rep = await ctx.client.post(LOGIN_URL, json=payload)
raise_for_status(rep, "login_two_factor_auth_challenge")
rep.raise_for_status()
return rep


Expand Down

0 comments on commit 9fa6343

Please sign in to comment.