python中文乱码问题可能出现在多种场景下,包括url请求中或者读写文件时。
1、url请求中可以使用 urllib.request.quote() 处理
import urllib.request
query = "汉字"
query = urllib.request.quote(query)
2、在写文件时可以对str进行编码再解码
str.encode('utf8').decode('utf8')
python中文乱码问题可能出现在多种场景下,包括url请求中或者读写文件时。
1、url请求中可以使用 urllib.request.quote() 处理
import urllib.request
query = "汉字"
query = urllib.request.quote(query)
2、在写文件时可以对str进行编码再解码
str.encode('utf8').decode('utf8')