[Solved] django mysql\base.py error: KeyError:

Tracking source code:

Problem file:Python36\lib\site-packages\django\db\backends\mysql\base.py

    def get_new_connection(self, conn_params):
        conn = Database. connect(** conn_params)
        conn.encoders[SafeText] = conn.encoders[six.text_type]
        conn.encoders[SafeBytes] = conn.encoders[bytes]
         return conn

 

solution

  1. Downgrade MySQLclient. Uninstall first, then install the specified version. pip3 uninstall mysqlclientpip3 install mysqlclient==1.3.
  2. My initial solution was to change the django code ( Python36\lib\site-packages\django\db\backends\mysql\base.py ), add an “if” as below:
    def get_new_connection(self, conn_params):
        conn = Database. connect(** conn_params)
        conn.encoders[SafeText] = conn.encoders[six.text_type] #First
         determine whether the bytes exist in the encoder, and if so, perform the operation 
        if bytes in conn.encoders:
            conn.encoders[SafeBytes] = conn.encoders[bytes]
         return conn
copy code

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *