From 6a10d0d11c02b0a4f361e098f07a6110d5a73115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=AA=E6=9D=A5=E5=8F=AF=E6=AC=BA?= <2513502304@qq.com> Date: Wed, 6 Aug 2025 11:24:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=9F=E5=A7=8B=E7=9A=84HTTPStatusError?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E6=8D=95=E8=8E=B7=E5=83=8FConnectError?= =?UTF-8?q?=E3=80=81ReadError=E8=BF=99=E4=BA=9B=E5=BC=82=E5=B8=B8=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=EF=BC=8C=E6=9C=AC=E6=AC=A1=E6=8F=90=E4=BA=A4=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=BA=86=E6=8D=95=E8=8E=B7=E5=BC=82=E5=B8=B8=E7=9A=84?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E4=B8=BAhttpx=E6=A8=A1=E5=9D=97=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E5=BC=82=E5=B8=B8=E7=9A=84=E5=9F=BA=E7=B1=BB=EF=BC=9A?= =?UTF-8?q?HTTPError=EF=BC=8C=E4=BB=A5=E4=BE=BF=E6=8D=95=E8=8E=B7=E5=9C=A8?= =?UTF-8?q?httpx.request=E6=96=B9=E6=B3=95=E4=B8=AD=E5=BC=95=E5=8F=91?= =?UTF-8?q?=E7=9A=84=E4=BB=BB=E4=BD=95=E5=BC=82=E5=B8=B8=EF=BC=88=E4=BE=8B?= =?UTF-8?q?=E5=A6=82ip=E8=A2=AB=E5=B0=81=EF=BC=8C=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=99=A8=E6=8B=92=E6=8E=A5=E8=BF=9E=E6=8E=A5=EF=BC=89=EF=BC=8C?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=E5=A4=84=E7=90=86=E7=88=AC=E5=8F=96=E5=AA=92?= =?UTF-8?q?=E4=BD=93=E8=A2=AB=E4=B8=AD=E6=96=AD=E6=97=B6=E5=B9=B6=E4=B8=8D?= =?UTF-8?q?=E4=BC=9A=E5=AF=BC=E8=87=B4=E7=88=AC=E5=8F=96=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E7=9A=84=E4=B8=AD=E6=96=AD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- media_platform/bilibili/client.py | 4 ++-- media_platform/douyin/client.py | 4 ++-- media_platform/weibo/client.py | 4 ++-- media_platform/xhs/client.py | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/media_platform/bilibili/client.py b/media_platform/bilibili/client.py index 1aed914..0abf872 100644 --- a/media_platform/bilibili/client.py +++ b/media_platform/bilibili/client.py @@ -210,8 +210,8 @@ class BilibiliClient(AbstractApiClient): return None else: return response.content - except httpx.HTTPStatusError as exc: # some wrong when call httpx.request method, such as connection error, client error or server error - utils.logger.error(f"[BilibiliClient.get_video_media] {exc}") + except httpx.HTTPError as exc: # some wrong when call httpx.request method, such as connection error, client error, server error or response status code is not 2xx + utils.logger.error(f"[BilibiliClient.get_video_media] {exc.__class__.__name__} for {exc.request.url} - {exc}") # 保留原始异常类型名称,以便开发者调试 return None async def get_video_comments( diff --git a/media_platform/douyin/client.py b/media_platform/douyin/client.py index 6722eef..46a3e8f 100644 --- a/media_platform/douyin/client.py +++ b/media_platform/douyin/client.py @@ -321,6 +321,6 @@ class DouYinClient(AbstractApiClient): return None else: return response.content - except httpx.HTTPStatusError as exc: # some wrong when call httpx.request method, such as connection error, client error or server error - utils.logger.error(f"[DouYinClient.get_aweme_media] {exc}") + except httpx.HTTPError as exc: # some wrong when call httpx.request method, such as connection error, client error, server error or response status code is not 2xx + utils.logger.error(f"[DouYinClient.get_aweme_media] {exc.__class__.__name__} for {exc.request.url} - {exc}") # 保留原始异常类型名称,以便开发者调试 return None diff --git a/media_platform/weibo/client.py b/media_platform/weibo/client.py index ee4b775..08c82da 100644 --- a/media_platform/weibo/client.py +++ b/media_platform/weibo/client.py @@ -256,8 +256,8 @@ class WeiboClient: return None else: return response.content - except httpx.HTTPStatusError as exc: # some wrong when call httpx.request method, such as connection error, client error or server error - utils.logger.error(f"[DouYinClient.get_aweme_media] {exc}") + except httpx.HTTPError as exc: # some wrong when call httpx.request method, such as connection error, client error, server error or response status code is not 2xx + utils.logger.error(f"[DouYinClient.get_aweme_media] {exc.__class__.__name__} for {exc.request.url} - {exc}") # 保留原始异常类型名称,以便开发者调试 return None async def get_creator_container_info(self, creator_id: str) -> Dict: diff --git a/media_platform/xhs/client.py b/media_platform/xhs/client.py index 2850c85..982373a 100644 --- a/media_platform/xhs/client.py +++ b/media_platform/xhs/client.py @@ -160,8 +160,8 @@ class XiaoHongShuClient(AbstractApiClient): return None else: return response.content - except httpx.HTTPStatusError as exc: # some wrong when call httpx.request method, such as connection error, client error or server error - utils.logger.error(f"[DouYinClient.get_aweme_media] {exc}") + except httpx.HTTPError as exc: # some wrong when call httpx.request method, such as connection error, client error, server error or response status code is not 2xx + utils.logger.error(f"[DouYinClient.get_aweme_media] {exc.__class__.__name__} for {exc.request.url} - {exc}") # 保留原始异常类型名称,以便开发者调试 return None async def pong(self) -> bool: