Python programming error solution: "AttributeError: 'str' object has no attribute 'decode'"

Introduction

When I was working on a django project, I encountered an error report like the title. Through search and analysis, it was a problem of encode/decode. My decode/encode did not appear in the code I wrote, but in D:\python\Lib\site-packages\django \db\backends\mysql\operations.py, which is the file displayed by the error.

Solution

1. Click to D:\python\Lib\site-packages\django\db\backends\mysql\operations.py in the operations.py where the error is reported 2.
Find the following code
insert image description here
3. There will be a prompt when query = query.decode(errors='replace')
changing to query = query.encode(errors='replace')
change, select The first to continue to change

Solve the error!

おすすめ

転載: blog.csdn.net/Ang_go/article/details/128968864