Skip to content

Login failure with TOTP-enabled procedure #393

Description

@tma-fritz

Description of the bug
pytr fails to login if TOTP ("Authenticator app") was enabled in the TR app.

Reproducer with log

$ uvx --with git+https://github.com/pytr-org/pytr pytr dl_docs -s --last_days 30 --v2 export
10:08:30 Using credentials from file /home/u1000/.pytr/credentials. Phone: +4917********, PIN: ****
10:08:30 Trying to resume websession...
10:08:30 Resuming websession failed.
10:08:30 Initiating web login...
10:08:30 WAF token skipped.
Enter the code from your authenticator app: <6 digits>
10:08:36 Logged in.
Traceback (most recent call last):
  File "/home/u1000/.cache/uv/archive-v0/nuulbc0jtt9D8WTE/bin/pytr", line 12, in <module>
    sys.exit(main())
             ~~~~^^
  File "/home/u1000/.cache/uv/archive-v0/nuulbc0jtt9D8WTE/lib/python3.14/site-packages/pytr/main.py", line 616, in main
    else login(
         ~~~~~^
        phone_no=args.phone_no,
        ^^^^^^^^^^^^^^^^^^^^^^^
    ...<3 lines>...
        v2=args.v2,
        ^^^^^^^^^^^
    ),
    ^
  File "/home/u1000/.cache/uv/archive-v0/nuulbc0jtt9D8WTE/lib/python3.14/site-packages/pytr/account.py", line 91, in login
    log.debug(get_settings(tr))
              ~~~~~~~~~~~~^^^^
  File "/home/u1000/.cache/uv/archive-v0/nuulbc0jtt9D8WTE/lib/python3.14/site-packages/pytr/account.py", line 14, in get_settings
    formatted_json = json.dumps(tr.settings(), indent=2)
                                ~~~~~~~~~~~^^
  File "/home/u1000/.cache/uv/archive-v0/nuulbc0jtt9D8WTE/lib/python3.14/site-packages/pytr/api.py", line 1021, in settings
    r = self._web_request("/api/v2/auth/account")
  File "/home/u1000/.cache/uv/archive-v0/nuulbc0jtt9D8WTE/lib/python3.14/site-packages/pytr/api.py", line 520, in _web_request
    r.raise_for_status()
    ~~~~~~~~~~~~~~~~~~^^
  File "/home/u1000/.cache/uv/archive-v0/nuulbc0jtt9D8WTE/lib/python3.14/site-packages/requests/models.py", line 1167, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.traderepublic.com/api/v1/auth/web/session

Environment

  • OS: Ubuntu
  • pytr version: 0.4.11 (GIT HEAD via uvx)

Additional context
I only enabled the TOTP recently in the TR app. 2 days ago, the "v2" login with just the app worked OK.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions