python 处理文章标签时,报编码错误
海之蓝091 发布于2018-10 浏览:2355 回复:3
0
收藏

$ python test.py 1
Traceback (most recent call last):
File "D:\phpStudy\WWW\git\clean\tool\baidu_ai.py", line 28, in getLabel
data = self.client.keyword(title,content)
File "C:\Python27\lib\site-packages\aip\nlp.py", line 201, in keyword
return self._request(self.__keywordUrl, data)
File "C:\Python27\lib\site-packages\aip\base.py", line 92, in _request
data = self._proccessRequest(url, params, data, headers)
File "C:\Python27\lib\site-packages\aip\nlp.py", line 66, in _proccessRequest
return json.dumps(data, ensure_ascii=False).decode('utf8').encode('gbk')
File "C:\Python27\lib\encodings\utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xd6 in position 13: invalid continuation byte

收藏
点赞
0
个赞
共3条回复 最后由求代课1357回复于2018-10
#4求代课1357回复于2018-10

可以试试强制编码转换,曾经试过

0
#3难挽之回复于2018-10

强制编码转换

0
#2lastAccomplice回复于2018-10

你在读取input的时候应该先以byte去读取在转换为utf8

0
TOP
切换版块