解决解码问题

This commit is contained in:
Jing Ling
2020-02-17 04:05:12 +08:00
parent f2ff9c166a
commit f9b706db4e
+9 -2
View File
@@ -92,9 +92,16 @@ async def fetch(session, url):
try: try:
# 先尝试用utf-8解码 # 先尝试用utf-8解码
text = await resp.text(encoding='utf-8', errors='replace') text = await resp.text(encoding='utf-8', errors='strict')
except UnicodeError: 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 return resp, text
except Exception as e: except Exception as e:
return e return e