mirror of
https://github.com/PaiGramTeam/HonkaiStarRailWikiDataParser.git
synced 2024-11-15 22:19:19 +00:00
🐛 fix: timeout error
This commit is contained in:
parent
6ea54ee5e0
commit
0c9f1f8b86
@ -5,11 +5,18 @@ from typing import Optional, Type
|
|||||||
import httpx
|
import httpx
|
||||||
|
|
||||||
__all__ = ("HTTPXRequest",)
|
__all__ = ("HTTPXRequest",)
|
||||||
|
timeout = httpx.Timeout(
|
||||||
|
timeout=120.0,
|
||||||
|
read=120.0,
|
||||||
|
write=120.0,
|
||||||
|
connect=120.0,
|
||||||
|
pool=120.0,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class HTTPXRequest(AbstractAsyncContextManager):
|
class HTTPXRequest(AbstractAsyncContextManager):
|
||||||
def __init__(self, *args, headers=None, **kwargs):
|
def __init__(self, *args, headers=None, **kwargs):
|
||||||
self._client = httpx.AsyncClient(headers=headers, timeout=httpx.Timeout(120.0), *args, **kwargs)
|
self._client = httpx.AsyncClient(headers=headers, timeout=timeout, *args, **kwargs)
|
||||||
|
|
||||||
async def __aenter__(self):
|
async def __aenter__(self):
|
||||||
try:
|
try:
|
||||||
@ -20,13 +27,14 @@ class HTTPXRequest(AbstractAsyncContextManager):
|
|||||||
raise exc
|
raise exc
|
||||||
|
|
||||||
async def __aexit__(
|
async def __aexit__(
|
||||||
self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]
|
self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException],
|
||||||
|
exc_tb: Optional[TracebackType]
|
||||||
) -> None:
|
) -> None:
|
||||||
await self.initialize()
|
await self.initialize()
|
||||||
|
|
||||||
async def initialize(self):
|
async def initialize(self):
|
||||||
if self._client.is_closed:
|
if self._client.is_closed:
|
||||||
self._client = httpx.AsyncClient()
|
self._client = httpx.AsyncClient(timeout=timeout)
|
||||||
|
|
||||||
async def shutdown(self):
|
async def shutdown(self):
|
||||||
if self._client.is_closed:
|
if self._client.is_closed:
|
||||||
|
@ -123,7 +123,7 @@ class Hyperion:
|
|||||||
_, file_extension = os.path.splitext(filename)
|
_, file_extension = os.path.splitext(filename)
|
||||||
is_image = bool(file_extension in ".jpg" or file_extension in ".png")
|
is_image = bool(file_extension in ".jpg" or file_extension in ".png")
|
||||||
response = await self.client.get(
|
response = await self.client.get(
|
||||||
url, params=self.get_images_params(resize=2000) if is_image else None, timeout=10, de_json=False
|
url, params=self.get_images_params(resize=2000) if is_image else None, de_json=False
|
||||||
)
|
)
|
||||||
return ArtworkImage(
|
return ArtworkImage(
|
||||||
art_id=art_id, page=page, file_name=filename, file_extension=url.split(".")[-1], data=response.content
|
art_id=art_id, page=page, file_name=filename, file_extension=url.split(".")[-1], data=response.content
|
||||||
|
Loading…
Reference in New Issue
Block a user