问题
I'm having problem to save accented letters. I'm using POSTGRESQL and Python 2.7
POSTGRESQL - ENCODING = 'LATIN1'
I already added this line but does not worked!
#!/usr/bin/python
# -*- coding: UTF-8 -*-
More about error message:
UnicodeDecodeError: 'utf8' codec can't decode byte 0xed
Please, any idea how to fix it?
@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 code is triggering the error. It's returning accent..
ob['CITY'] = row[2]
回答1:
First thing to check is whether your "accented letters" belong to LATIN1 set - for example, á does, but ś doesn't. If not, you really should use UTF8 encoding in PostgreSQL (it is probably safer anyway).
来源:https://stackoverflow.com/questions/44347924/python-unicodedecodeerror-utf8