Linked Questions
23 questions linked to/from UnicodeDecodeError when redirecting to file
183
votes
16
answers
142k
views
Python, Unicode, and the Windows console
When I try to print a string in a Windows console, sometimes I get an error that says UnicodeEncodeError: 'charmap' codec can't encode character ..... I assume this is because the Windows console ...
89
votes
7
answers
81k
views
How to set sys.stdout encoding in Python 3?
Setting the default output encoding in Python 2 is a well-known idiom:
sys.stdout = codecs.getwriter("utf-8")(sys.stdout)
This wraps the sys.stdout object in a codec writer that encodes output in UTF-...
56
votes
4
answers
39k
views
Python UnicodeDecodeError - Am I misunderstanding encode?
Any thoughts on why this isn't working? I really thought 'ignore' would do the right thing.
>>> 'add \x93Monitoring\x93 to list '.encode('latin-1','ignore')
Traceback (most recent call last)...
35
votes
4
answers
116k
views
Convert an int value to unicode
I am using pyserial and need to send some values less than 255. If I send the int itself the the ascii value of the int gets sent. So now I am converting the int into a unicode value and sending it ...
21
votes
4
answers
21k
views
How to change the stdin and stdout encoding on Python 2
I'm using Windows and Linux machines for the same project. The default encoding for stdin on Windows is cp1252, and on Linux it is utf-8.
I would like to change everything to utf-8.
Is it possible? ...
3
votes
3
answers
5k
views
Python encoding - Is there any explanation?
Can someone explain to me why python has this behaviour?
Let's me explain.
BACKGROUND
I have a python installation and I want to use some chars that aren't in the ASCII table.
So I change my python ...
8
votes
6
answers
6k
views
How to print symbols like ●くろまる to files in Python
I'm trying to write the symbol ●くろまる to a text file in python. I think it has something to do with the encoding (utf-8). Here is the code:
# -*- coding: utf-8 -*-
outFile = open('./myFile.txt', 'wb')
...
2
votes
4
answers
13k
views
Python utf-coding problem with command line
For the past few days I've been learning programing with Python and I'm still but a beginner. Recently, I've used the book 'Code in the cloud' for that purpose. The thing is, while all those textbooks ...
1
vote
1
answer
7k
views
How do I fix "UnicodeEncodeError: 'cp950' codec can't encode character '\u7dab' in position 19: illegal multibyte sequence"
I was trying to get data from the website and input it into csv
table_array = []
def get_data(page):
url = "https://www.sl886.com/stockrating/list?list=stockrating&page=" + str(page)...
7
votes
2
answers
2k
views
Error occurs when trying to redirect Python UTF-8 stdout to a file on Windows
When I try to redirect a UTF-8 stdout in Powershell by running python3 .\test.py > test.txt, error occurs :
UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-1: character ...
-1
votes
1
answer
5k
views
how to read both ANSI and Unicode txt files in Python?
I'm new to python and face a strange problem:
When I have 50 txt files in a directory, I want to read each .txt file and save its content in a unique variable like:
**file = open(fcf[i], 'r')
text[i]...
0
votes
1
answer
2k
views
encoding problem with pgsql/python?
I retrieved a bunch of text records from my postgresql database and intend to preprocess these text documents before analyzing them.
I want to tokenize the documents but ran into some problem during ...
5
votes
3
answers
1k
views
UnicodeEncodeError in python3 when redirection is used
What I want to do: extract text information from a pdf file and redirect that to a txt file.
What I did:
pip install pdfminor
pdf2txt.py file.pdf > output.txt
What I got:
UnicodeEncodeError: '...
1
vote
2
answers
2k
views
decoding unicode string variables in Python
I am using an API in Python v2.7 to obtain a string, the content of which is unknown. The content can be in English, German or French. The variable name assigned to the returned string is 'category'. ...
0
votes
1
answer
1k
views
UnicodeDecodeError: 'ascii' codec cant decode byte 0xef in position 2141: ordinal not in range(128)
This is a script that sends randomly generated sentences into a discord chat. But it occasionally runs into the error: UnicodeDecodeError: 'ascii' codec cant decode byte 0xef in position 2141: ...