AttributeError: 'str' object has no attribute 'ecode'
程序员文章站
2022-04-14 09:31:21
...
query = query.decode(errors='replace')
报错:AttributeError: 'str' object has no attribute 'decode'
通常情况下,根据提示打开报错的文件operations.py,将 146 行改为:query = query.ecode(errors='replace')
如果还报错:AttributeError: 'str' object has no attribute 'ecode',则用以下方法尝试解决
原因:
python3默认的编码就是unicode,这个跟python2不太一样,如果直接给字符串decode会报错:AttributeError: 'str' object has no attribute 'ecode'
解决方法:
python3 先encode成utf-8编码,再decode成默认的unicode就可以了
类似的:
c = "%u4E0A%u6D77%u60A0%u60A0"
query = c.replace("%", "\\")
query = query.encode("utf-8").decode(errors='replace')
上一篇: AttributeError: 'dict' object has no attribute 'iteritems'
下一篇: AttributeError: ‘tuple‘ object has no attribute ‘layer‘
推荐阅读
-
python错误:AttributeError: 'module' object has no attribute 's
-
python编程排除163邮箱发送邮件报错(AttributeError: ‘tuple‘ object has no attribute ‘encode‘)
-
python编程排除163邮箱发送邮件报错(AttributeError: ‘tuple‘ object has no attribute ‘encode‘)
-
AttributeError: module ‘community‘ has no attribute ‘best_partition‘ 问题解决方法
-
【python】解决AttributeError: module ‘scipy.misc‘ has no attribute ‘toimage‘问题
-
【Tensorflow】Linux下Tensorflow报错:AttributeError: module ‘tensorflow‘ has no attribute ‘xxxx‘
-
AttributeError: 'module' object has no attribute 'main'
-
AttributeError: module 'sklearn' has no attribute 'linear_model'
-
解决Keras报错AttributeError: 'NoneType' object has no attribute 'inbound_nodes'
-
解决'DataFrame' object has no attribute 'sort'