Python: UnicodeDecodeError: 'utf8'

I have a problem with keeping letters with an accent. I am using POSTGRESQL and Python 2.7

POSTGRESQL - ENCODING = 'LATIN1' 

I already added this line, but it will not work!

 #!/usr/bin/python # -*- coding: UTF-8 -*- 

Details of the error message:

 UnicodeDecodeError: 'utf8' codec can't decode byte 0xed 

Please any idea how to fix this?

@Edit:

 cur = conn.cursor() cur.execute("SELECT * FROM users") rows = cur.fetchall() obj_list = list() for row in rows: ob = dict() ob['ID'] = row[0] ob['NAME'] = row[1] ob['CITY'] = row[2] ob['USERNAME'] = row[3] obj_list.append(ob) # print obj_list # sys.exit() def add_object(ob, row): ws.cell(column=3, row=row).value = ob['ID'] ws.cell(column=4, row=row).value = ob['NAME'] ws.cell(column=6, row=row).value = ob['CITY'] ws.cell(column=8, row=row).value = ob['USERNANE'] 

This part of the code is causing an error. It returns the accent ..

 ob['CITY'] = row[2] 
-1
source share
1 answer

First of all, check if your "accented letters" belong to the LATIN1 set, for example, à, but ś not. If not, you really should use UTF8 encoding in PostgreSQL (this is probably safe anyway).

+1
source

All Articles