mirror of
https://github.com/flibusta-apps/books_downloader.git
synced 2025-12-06 15:05:37 +01:00
Fix closing client
This commit is contained in:
@@ -54,8 +54,7 @@ class BookLibraryClient:
|
|||||||
@classmethod
|
@classmethod
|
||||||
async def _make_request(cls, url) -> dict:
|
async def _make_request(cls, url) -> dict:
|
||||||
async with httpx.AsyncClient(timeout=60) as client:
|
async with httpx.AsyncClient(timeout=60) as client:
|
||||||
response = await client.get(url, headers=cls.auth_headers)
|
return (await client.get(url, headers=cls.auth_headers)).json()
|
||||||
return response.json()
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def get_sources(cls) -> list[Source]:
|
async def get_sources(cls) -> list[Source]:
|
||||||
|
|||||||
@@ -83,17 +83,13 @@ class FLDownloader(BaseDownloader):
|
|||||||
content_type = response.headers.get("Content-Type")
|
content_type = response.headers.get("Content-Type")
|
||||||
|
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
await response.aclose()
|
|
||||||
await client.aclose()
|
|
||||||
raise NotSuccess(f"Status code is {response.status_code}!")
|
raise NotSuccess(f"Status code is {response.status_code}!")
|
||||||
|
|
||||||
if "text/html" in content_type:
|
if "text/html" in content_type:
|
||||||
await response.aclose()
|
|
||||||
await client.aclose()
|
|
||||||
raise ReceivedHTML()
|
raise ReceivedHTML()
|
||||||
|
|
||||||
return client, response, "application/zip" in content_type
|
return client, response, "application/zip" in content_type
|
||||||
except asyncio.CancelledError:
|
except (asyncio.CancelledError, NotSuccess, ReceivedHTML):
|
||||||
await client.aclose()
|
await client.aclose()
|
||||||
await client.aclose()
|
await client.aclose()
|
||||||
raise
|
raise
|
||||||
@@ -224,7 +220,7 @@ class FLDownloader(BaseDownloader):
|
|||||||
raise ConvertationError
|
raise ConvertationError
|
||||||
|
|
||||||
return converter_client, converter_response, False
|
return converter_client, converter_response, False
|
||||||
except asyncio.CancelledError:
|
except (asyncio.CancelledError, ConvertationError):
|
||||||
await converter_response.aclose()
|
await converter_response.aclose()
|
||||||
await converter_client.aclose()
|
await converter_client.aclose()
|
||||||
await aiofiles.os.remove(filename_to_convert)
|
await aiofiles.os.remove(filename_to_convert)
|
||||||
|
|||||||
Reference in New Issue
Block a user