Convert a list with wrong encoding to utf8

vergos.nikolas at gmail.com vergos.nikolas at gmail.com
Thu Feb 14 15:11:40 EST 2019


I'm using Python3 and pymysql and already have charset presnt

[python]
con = pymysql.connect( db = 'clientele', user = 'vergos', passwd = '******', charset = 'utf8' )
cur = con.cursor()
[/python]

>From that i understand that the names being fetched from the db to pyhton script are being fetced as utf8, right?

I dont convert, format the string in the meanwhile. Python3 handles the encoidng and i dont know from where latin iso get into the middle but when i

[python]names = tuple( [s.encode('latin1').decode('utf8') for s in names] )[/python]

[output]UnicodeEncodeError('latin-1', 'Άκης Τσιάμης', 0, 4, 'ordinal not in range(256)')[/output]

which is a perfectly valid names but still gives an error.

Also the strings produced '\xce\x86\xce\xba\xce\xb7\xcf\x82 \xce\xa4\xcf\x83\xce\xb9\xce\xac\xce\xbc\xce\xb7\xcf\x82' are strings not raw bytes.

WHY Python3 instead of fetching the values from the db as 'utf8' it stores the values in hex representation?



More information about the Python-list mailing list