From f9b706db4e29df84475b32b0f0c8a5a6b80a9767 Mon Sep 17 00:00:00 2001 From: Jing Ling Date: Mon, 17 Feb 2020 04:05:12 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E8=A7=A3=E7=A0=81=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oneforall/common/request.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/oneforall/common/request.py b/oneforall/common/request.py index b21b6fd..dcf5b74 100644 --- a/oneforall/common/request.py +++ b/oneforall/common/request.py @@ -92,9 +92,16 @@ async def fetch(session, url): try: # 先尝试用utf-8解码 - text = await resp.text(encoding='utf-8', errors='replace') + text = await resp.text(encoding='utf-8', errors='strict') except UnicodeError: - text = await resp.text(encoding='gb18030', errors='replace') + try: + # 再尝试用gb18030解码 + text = await resp.text(encoding='gb18030', + errors='strict') + except UnicodeError: + # 最后尝试自动解码 + text = await resp.text(encoding=None, + errors='ignore') return resp, text except Exception as e: return e