mirror of
https://github.com/shmilylty/OneForAll.git
synced 2026-10-29 12:35:52 +08:00
解决解码问题
This commit is contained in:
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user