tlocke / pg8000

A Pure-Python PostgreSQL Driver
BSD 3-Clause "New" or "Revised" License
515 stars 46 forks source link

UnicodeDecodeError in error messages #73

Closed epogrebnyak closed 3 years ago

epogrebnyak commented 3 years ago

Thank for your work on such a useful driver! I'm into an encoding problem that manifests on Windows console:

File "/mnt/c/Users/epogr/Documents/GitHub/rides-blueprint/.venv/lib/python3.8/site-packages/pg8000/core.py", line 353, in <genexpr>
    (s[:1].decode(self._client_encoding), s[1:].decode(self._client_encoding))
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc2 in position 0: invalid continuation byte 
tlocke commented 3 years ago

Glad you find it useful @epogrebnyak :-)

The problem you ran into is caused by the server returning an invalid error string (it's got a byte in there that's not valid utf-8), so in version 1.19.5 which I've just released, it substitutes in the unicode replacement character � for any invalid characters, instead of raising an exception. Let me know if that doesn't work out.