Fixing autoremove-torrents LoginFailure with qBittorrent HTTP 204

Help with operating systems, apps, and software-related issues.
User avatar
ccb056
Site Administrator
Posts: 1004
Joined: January 14th, 2004, 11:36 pm
Location: Texas

Fixing autoremove-torrents LoginFailure with qBittorrent HTTP 204

Post by ccb056 »

I ran into an issue on my server after installing autoremove-torrents 1.5.5 inside a Python virtualenv.

The error looked like this:

Code: Select all

autoremovetorrents.exception.loginfailure.LoginFailure: The server returned HTTP 204.
This appears to be caused by newer qBittorrent Web API behavior. Newer qBittorrent versions can return HTTP 204 on successful login, but autoremove-torrents 1.5.5 only treats HTTP 200 as a successful login.

There is an upstream pull request that fixes this by accepting any HTTP 2xx response instead of only 200:
https://github.com/jerrymakesjelly/auto ... issues/210
https://github.com/jerrymakesjelly/auto ... s/pull/211


1. Activate the virtualenv

Code: Select all

source ~/virtualenv/bin/activate
2. Locate the installed qBittorrent client file

Code: Select all

python - <<'PY'
import inspect
import autoremovetorrents.client.qbittorrent as q
print(inspect.getsourcefile(q))
PY
3. Patch the login status-code check

The broken check only accepts HTTP 200:

Code: Select all

if request.status_code == 200:
It needs to be changed to accept any successful HTTP 2xx response:

Code: Select all

if 200 <= request.status_code < 300:
I used this command to patch it automatically:

Code: Select all

FILE=$(python - <<'PY'
import inspect
import autoremovetorrents.client.qbittorrent as q
print(inspect.getsourcefile(q))
PY
)

cp "$FILE" "$FILE.bak.$(date +%Y%m%d%H%M%S)"

python - <<PY
from pathlib import Path

path = Path("$FILE")
text = path.read_text()

old = "if request.status_code == 200:"
new = "if 200 <= request.status_code < 300:"

if old not in text:
    raise SystemExit(f"Did not find expected line in {path}")

path.write_text(text.replace(old, new, 1))
print(f"Patched {path}")
PY
This makes autoremove-torrents treat HTTP 204 as a successful login instead of throwing a login failure.