python3 encounters a problem with the Byte conversion string containing \x on the windows platform

Forwarding address: http://www.bejson.com/convert/ox2str/

Hehe, just giving a conversion address is useful. Is it possible that I still need to convert each word?

Then, after checking for a long time, I found the problem of python3 printing under the windows platform, that is, the default output encoding of print is GBK, and we need to change it to UTF-8.

import urllib.request
import json
import io
import sys

# 修改一下print的默认编码,默认是gbk
sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf8')

api_url = "http://www.xxx.com"
resp = urllib.request.urlopen(api_url).read()
res = json.loads(resp)
print(res)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325826597&siteId=291194637