Python Forum

Full Version: UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 error from Mysql call
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Python3, Ubuntu 20.04

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92

When querying the MySQL database I receive this error, the code was working under Python2.7 but not in Python3.

appointments = App_Connection().Query_All("SELECT * FROM `ea_appointments` WHERE `id` > '%s'" % (record_num,))


class App_Connection(object):
    def __init__(self, host="xx.xxx.x.xxx", user="_app", passwd="", db="appoint"):
        self.host = host
        self.user = user
        self.passwd = passwd
        self.dbc = db
        self.connection()

    def connection(self):
        self.connection = MySQLdb.connect(self.host, self.user, self.passwd, self.dbc)

    def Query_All(self, sql_statement):
        cursor = self.connection.cursor()
        cursor.execute(sql_statement)
        result = cursor.fetchall()
        cursor.close()
        return result

    def Query_One(self, sql_statement):
        cursor = self.connection.cursor()
        cursor.execute(sql_statement)
        result = cursor.fetchone()
        cursor.close()
        return result

    def Commit(self, sql_statement):
        cursor = self.connection.cursor()
        cursor.execute(sql_statement)
        self.connection.commit()
        cursor.close()
This must be a MySQLdb thing as I have changed module to
import pymysql
and it works as expected