From b4c4ffcfe8c13539fa958914e4449f040e92d2e8 Mon Sep 17 00:00:00 2001 From: NeoMod Date: Thu, 14 May 2026 20:05:47 +0200 Subject: [PATCH] Fix: qbit-204-auth-error --- backend/app/clients/qbittorrent.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/backend/app/clients/qbittorrent.py b/backend/app/clients/qbittorrent.py index 9bcd719..d242ef7 100644 --- a/backend/app/clients/qbittorrent.py +++ b/backend/app/clients/qbittorrent.py @@ -48,9 +48,18 @@ async def _ensure_authenticated(self): try: data = {"username": self.username, "password": self.password} - - async with self.session.post(f"{self.url}/api/v2/auth/login", data=data) as response: - if response.status == 200: + headers = {"Referer": self.url} + + async with self.session.post( + f"{self.url}/api/v2/auth/login", + data=data, + headers=headers, + ) as response: + # qBittorrent >= 5.2 may return 204 No Content for successful login. + if response.status == 204: + self._authenticated = True + logger.debug("Authenticated with qBittorrent") + elif response.status == 200: text = await response.text() if text.strip() == "Ok.": self._authenticated = True @@ -70,7 +79,7 @@ async def _request(self, method: str, endpoint: str, retry_on_auth_failure: bool response = await self.session.request(method, url, **kwargs) if response.status == 403 and retry_on_auth_failure: - await response.release() + response.release() logger.info("qBittorrent returned 403, re-authenticating...") self._authenticated = False await self._ensure_authenticated()