prestodb / presto-python-client

Python DB-API client for Presto
Apache License 2.0
239 stars 87 forks source link

Unicode characters are not supported in Presto cursors #99

Open larandvit opened 4 years ago

larandvit commented 4 years ago

Hello,

It seems Unicode characters are not supported in cursors. When a Presto table has Unicode characters, UnicodeEncodeError error comes up during retrieval of cursor values. cp1252 encoding is applied. Is there any setting to apply utf-8 encoding?

Error message

Traceback (most recent call last):
  File "C:\\Code\prestodb_stats.py", line 146, in <module>
    print(field)
  File "C:\Program Files\Python36\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\uffe5' in position 0: character maps to <undefined>

Code

conn = prestodb.dbapi.connect(**con_config)
cur = conn.cursor()
cur.execute(sql_text)
rows = cur.fetchall()

for row in rows:
      for field in row:
           print(field)

For example, Unicode value is .

Thank you.