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)

 

你可能感兴趣的:(python)