Skip to content

Fix qBittorrent 5.x login failure - #99

Merged
idlesign merged 2 commits into
idlesign:masterfrom
GriffTanen:fix/qbittorrent-5x-login
Aug 29, 2026
Merged

idlesign merged 2 commits into
idlesign:masterfrom
GriffTanen:fix/qbittorrent-5x-login

Conversation

@GriffTanen

Copy link
Copy Markdown
Contributor

Description

configure_rpc qbittorrent and any subsequent RPC call fail against qBittorrent 5.x with a confusing message:

ERROR: QBittorrentRPC: Failed to query RPC `http://<host>:8068/api/v2/auth/login`: OK
ERROR: QBittorrentRPC: Failed to login using `http://<host>:8068/api/v2/` RPC: OK
ERROR: Walk failed. Reason: OK

The credentials are correct — the login actually succeeds. qBittorrent 5.x replies to /api/v2/auth/login with HTTP 204 and an empty body, while earlier versions replied 200 with the body Ok.:

HTTP/1.1 204 OK
set-cookie: QBT_SID_8068=...; HttpOnly; path=/

Two checks reject that valid response:

  1. query() — if response.status_code != 200: treats 204 as a failure and raises with response.text.strip() or response.reason. The body is empty, so the message becomes the reason phrase OK, which is why the errors above read Reason: OK.
  2. login() — if result.text != 'Ok.' requires the exact Ok. body, which 5.x no longer sends.

Changes

  • query() accepts any 2xx status instead of exactly 200.
  • login() treats an empty body as success alongside Ok., so both qBittorrent 4.x and 5.x work.

Verification

Tested against qBittorrent 5.1.4 (Web API on port 8068), torrt 1.2.0, Python 3.12.

Before the change torrt walk fails at login. After:

INFO: Torrent walk is triggered
INFO: Torrent walk is started
INFO: Getting torrents from `qbittorrent` ...
INFO:   Processing `Lanterns (Season 1) WEB-DL 1080p`...
INFO:     No updates
INFO: Torrent walk is finished

add_torrent also works end to end — the torrent is fetched from the tracker and added to the client:

INFO: Torrent from `https://rutracker.org/forum/viewtopic.php?t=...` is added within `qbittorrent`

Database Migration

NO

qBittorrent 5.x replies to /auth/login with HTTP 204 and an empty body,
while earlier versions replied 200 with the body `Ok.`. Both checks in
QBittorrentRPC rejected that valid response:

- query() treated any non-200 status as an error, so 204 raised with
  `response.reason` ("OK") as the message, producing the confusing
  "Failed to login ...: OK" output;
- login() required the body to equal `Ok.`.

Accept any 2xx status and treat an empty body as success alongside `Ok.`.
Verified against qBittorrent 5.1.4: login and `walk` now work.
@idlesign

Copy link
Copy Markdown
Owner

Thank you. I'd like to ask you to add a test for this scenario.

@coveralls

coveralls commented Aug 28, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 33210945552

Coverage increased (+0.3%) to 67.972%

Details

  • Coverage increased (+0.3%) from the base build.
  • Patch coverage: 2 of 2 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 1686
Covered Lines: 1146
Line Coverage: 67.97%
Coverage Strength: 3.86 hits per line

💛 - Coveralls

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 33127488465

Coverage remained the same at 67.675%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: 2 of 2 lines across 1 file are fully covered (100%).
  • 1 coverage regression across 1 file.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

1 previously-covered line in 1 file lost coverage.

File Lines Losing Coverage Coverage
src/torrt/rpc/qbittorrent.py 1 87.63%

Coverage Stats

Coverage Status
Relevant Lines: 1686
Covered Lines: 1141
Line Coverage: 67.67%
Coverage Strength: 3.85 hits per line

💛 - Coveralls

test_login_qbittorrent_5 covers the 204 empty-body reply: it fails on the
unpatched code with "Failed to login ...: No Content" and passes with the fix.

test_login_failed keeps the negative path covered, so an unexpected body is
still reported as an authentication failure.
@GriffTanen

Copy link
Copy Markdown
Contributor Author

Sure — added in d6793cc.

test_login_qbittorrent_5 covers the reported scenario: a login answered with 204 and an empty body, followed by a regular call to confirm the session is usable. It fails on the unpatched code with

Failed to login using `http://localhost:8080/api/v2/` RPC: No Content

and passes with the fix.

test_login_failed keeps the negative path covered, so an unexpected body is still reported as an authentication failure rather than being swallowed by the widened check.

Both use the existing response_mock style of the module. Locally the qBittorrent suite goes 5 → 7 passed; the 4 unrelated failures I see (test_main.py::test_fullcycle and the eniahd/kinozal/nnmclub tracker tests) are present on the branch point too, so they are not caused by this PR.

@idlesign
idlesign merged commit dcc9914 into idlesign:master Aug 29, 2026
7 checks passed
@idlesign

Copy link
Copy Markdown
Owner

Thank you. Merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants