Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions backend/app/clients/qbittorrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down