Python: UnicodeDecodeError: utf8

2024/10/6 12:21:35

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]    
Answer

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://en.xdnf.cn/q/118952.html

Related Q&A

Get continuous response of POST request in python

Im writing a script which does a POST request to a server and gets blocked the server keeps sending the response whenever a specific event is triggered. I have to take a cookie for post request with ea…

DataType of Pandas Multiindex [duplicate]

This question already has answers here:get the dtype of a pandas multiindex(3 answers)Closed 6 years ago.import pandas as pd index = pd.MultiIndex.from_tuples([(1,2, None), (1,2,3)]) print(index.get_le…

Is there a way to see the internal representation of float?

In python tutorial for floating point, In base 2, 1/10 is the infinitely repeating fraction0.0001100110011001100110011001100110011001100110011...How do I get python interpreter to print this intenal re…

Create function from try-except

Based on the example provided in this answer, how can I create a function from:from collections import Counter s = [0, 0, 2, 1, 1, 0, 0, 0] try:print(next(t[0] for t in Counter(s).most_common(2) if t[…

Bad request error flask with POST request

I have the following route that is getting values from a submitted form@app.route(/authenticate, methods=["POST"]) def authenticate():username = request.form[username]print(username, file = s…

How to use matplotlib/numpy to plot heatmap given three irregular lists of values in Python

Im wondering if there is a way to use matplotlib and numpy to plot the heatmap of three lists. My grid is not regular, it is oddly shaped so this does not work for me: Plotting a Heat Map X,Y,Intensity…

How to set custom color for symbols like*,#,etc in python tkinter

How to set specific color for certain symbols like ,#,etc example if I type "" its color should be blue and other stay remain same. typedecker sir i am binding you function like this but thi…

How can I get only heading names.from the text file

I have a Text file as below:Education: askdjbnakjfbuisbrkjsbvxcnbvfiuregifuksbkvjb.iasgiufdsegiyvskjdfbsldfgdTechnical skills : java,j2ee etc.,work done: oaugafiuadgkfjwgeuyrfvskjdfviysdvfhsdf,aviysdvw…

Concatenate list elements that fall between list elements of certain value

Imagine I have the following list:>>> mylist[(a, uDT),(Satisfactory, uJJ),(tracing, uVBG),(with, uIN),(a, uDT),(fairly, uRB),(persistent, uJJ),(with, uIN)]How do I concatenate list items that …

How to create list from 100 elements to list of 10 [duplicate]

This question already has answers here:How to iterate over a list in chunks(40 answers)Closed 4 years ago.I have small brain fade today and I believe it will be faster to get hint here than wondering f…