Python Forum
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 error from Mysql call - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 error from Mysql call (/thread-33463.html)



UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 error from Mysql call - AkaAndrew123 - Apr-27-2021

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()



RE: UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 error from Mysql call - AkaAndrew123 - Apr-28-2021

This must be a MySQLdb thing as I have changed module to
import pymysql
and it works as expected