mirror of
https://github.com/shmilylty/OneForAll.git
synced 2026-08-26 04:47:48 +08:00
修复解码问题
This commit is contained in:
+12
-6
@@ -719,11 +719,17 @@ def get_url_resp(url):
|
|||||||
|
|
||||||
|
|
||||||
def decode_resp_text(resp):
|
def decode_resp_text(resp):
|
||||||
|
content = resp.content
|
||||||
|
if not content:
|
||||||
|
return str('')
|
||||||
try:
|
try:
|
||||||
text = resp.text(encoding='utf-8', errors='strict') # 先尝试用utf-8严格解码
|
# 先尝试用utf-8严格解码
|
||||||
except UnicodeError:
|
content = str(content, encoding='utf-8', errors='strict')
|
||||||
|
except (LookupError, TypeError, UnicodeError):
|
||||||
try:
|
try:
|
||||||
text = resp.text(encoding='gb18030', errors='strict') # 再尝试用gb18030严格解码
|
# 再尝试用gb18030严格解码
|
||||||
except UnicodeError:
|
content = str(content, encoding='gb18030', errors='strict')
|
||||||
text = resp.text(encoding=None, errors='ignore') # 最后尝试自动解码
|
except (LookupError, TypeError, UnicodeError):
|
||||||
return text
|
# 最后尝试自动解码
|
||||||
|
content = str(content, errors='replace')
|
||||||
|
return content
|
||||||
|
|||||||
Reference in New Issue
Block a user