django-pyodbc-azure icon indicating copy to clipboard operation
django-pyodbc-azure copied to clipboard

Handle decode charset error

Open JosephDev opened this issue 8 years ago • 2 comments

base.py line 561 - 571

def format_row(self, row):
    """
    Decode data coming from the database if needed and convert rows to tuples
    (pyodbc Rows are not sliceable).
    """
    if self.driver_charset:
        for i in range(len(row)):
            f = row[i]
            # FreeTDS (and other ODBC drivers?) doesn't support Unicode
            # yet, so we need to decode utf-8 data coming from the DB
            if isinstance(f, binary_type):
                row[i] = f.decode(self.driver_charset)
    return row

In case fail to decode, it raise error. What if we decode with error ignore option like f.decode(self.driver_charset, errors ='ignore')

If you need, I am going to make PR.

JosephDev avatar Feb 26 '17 05:02 JosephDev

getting this error: is it related?

UnicodeDecodeError: 'utf-16-le' codec can't decode bytes in position 22-23: unexpected end of data

sean29 avatar Nov 29 '17 23:11 sean29

@sean29 Were you able to solve this?

Edit: I was getting this because of inputting invalid value in the geography field in MSSQL database

singhravi1 avatar Jun 01 '19 12:06 singhravi1