From 499cf26fa84b13e6aad4ccdf160d552216423cd3 Mon Sep 17 00:00:00 2001 From: taizan-hokouto <55448286+taizan-hokuto@users.noreply.github.com> Date: Mon, 26 Oct 2020 23:39:33 +0900 Subject: [PATCH] Integrate httpx exceptions --- pytchat/core_async/livechat.py | 2 +- pytchat/core_multithread/livechat.py | 2 +- pytchat/tool/extract/asyncdl.py | 5 ++--- pytchat/tool/videoinfo.py | 3 +-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/pytchat/core_async/livechat.py b/pytchat/core_async/livechat.py index 8feb8df..85e5c18 100644 --- a/pytchat/core_async/livechat.py +++ b/pytchat/core_async/livechat.py @@ -249,7 +249,7 @@ class LiveChatAsync: resp = await client.get(url, headers=headers) livechat_json = resp.json() break - except (httpx.HTTPError, json.JSONDecodeError): + except (json.JSONDecodeError, httpx.HTTPError): await asyncio.sleep(1) continue else: diff --git a/pytchat/core_multithread/livechat.py b/pytchat/core_multithread/livechat.py index eb49086..f82d5a8 100644 --- a/pytchat/core_multithread/livechat.py +++ b/pytchat/core_multithread/livechat.py @@ -241,7 +241,7 @@ class LiveChat: try: livechat_json = client.get(url, headers=headers).json() break - except (json.JSONDecodeError, httpx.TimeoutError): + except (json.JSONDecodeError, httpx.HTTPError): time.sleep(2) continue else: diff --git a/pytchat/tool/extract/asyncdl.py b/pytchat/tool/extract/asyncdl.py index ab6fca3..a4c52e8 100644 --- a/pytchat/tool/extract/asyncdl.py +++ b/pytchat/tool/extract/asyncdl.py @@ -9,7 +9,6 @@ from ... import config from ... paramgen import arcparam from ... exceptions import UnknownConnectionError from concurrent.futures import CancelledError -from httpx import NetworkError, TimeoutException, ConnectError from json import JSONDecodeError from urllib.parse import quote @@ -81,7 +80,7 @@ def ready_blocks(video_id, duration, div, callback): break except JSONDecodeError: await asyncio.sleep(3) - except (NetworkError, TimeoutException, ConnectError) as e: + except httpx.HTTPError as e: err = e await asyncio.sleep(3) else: @@ -137,7 +136,7 @@ def fetch_patch(callback, blocks, video_id): break except JSONDecodeError: await asyncio.sleep(3) - except (NetworkError, TimeoutException, ConnectError) as e: + except httpx.HTTPError as e: err = e await asyncio.sleep(3) except socket.error as error: diff --git a/pytchat/tool/videoinfo.py b/pytchat/tool/videoinfo.py index 722a619..8e789b6 100644 --- a/pytchat/tool/videoinfo.py +++ b/pytchat/tool/videoinfo.py @@ -2,7 +2,6 @@ import httpx import json import re import time -from httpx import ConnectError, NetworkError, TimeoutException from .. import config from ..exceptions import InvalidVideoIdException, PatternUnmatchError, UnknownConnectionError from ..util.extract_video_id import extract_video_id @@ -107,7 +106,7 @@ class VideoInfo: resp = httpx.get(url, headers=headers) resp.raise_for_status() break - except (ConnectError, NetworkError, TimeoutException) as e: + except httpx.HTTPError as e: err = e time.sleep(3) else: