pymysql的解碼bug修復,解決decode error

使用pymysql 出現utf-8  codec can't decode bytes

找到pymysql安裝包的源碼

修改pymysql下的connections腳本,pymysql從數據庫拿記錄進行轉碼沒有進行異常處理。

    def _read_row_from_packet(self, packet):
        row = []
        for encoding, converter in self.converters:
            try:
                data = packet.read_length_coded_string()
            except IndexError:
                # No more columns in this row
                # See https://github.com/PyMySQL/PyMySQL/pull/434
                break
            if data is not None:
                if encoding is not None:
                    # data = data.decode(encoding)
                    data = data.decode(encoding ,'ignore')
                if DEBUG: print("DEBUG: DATA = ", data)
                if converter is not None:
                    data = converter(data)
            row.append(data)
        return tuple(row)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章