欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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就可以了

AttributeError: 'str' object has no attribute 'ecode'

AttributeError: 'str' object has no attribute 'ecode' 

类似的:

c = "%u4E0A%u6D77%u60A0%u60A0"
query = c.replace("%", "\\")

query = query.encode("utf-8").decode(errors='replace')