python-unicode

UnicodeDecodeError when reading file in Python

UnicodeDecodeError when reading file in Python Question: I am currently learning Python and came across the following error: Traceback (most recent call last): File "file.py", line 22, in module for word in file.read(): File "C:UsersuserAppDataLocalContinuumAnaconda3libencodingscp1252.py" line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: ‘charmap’ codec can’t decode byte 0x9d in position 6552: character maps to undefined …

Total answers: 1

how to convert Python 2 unicode() function into correct Python 3.x syntax

how to convert Python 2 unicode() function into correct Python 3.x syntax Question: I enabled the compatibility check in my Python IDE and now I realize that the inherited Python 2.7 code has a lot of calls to unicode() which are not allowed in Python 3.x. I looked at the docs of Python2 and found …

Total answers: 5

Unicode Encode Error when writing pandas df to csv

Unicode Encode Error when writing pandas df to csv Question: I cleaned 400 excel files and read them into python using pandas and appended all the raw data into one big df. Then when I try to export it to a csv: df.to_csv(“path”,header=True,index=False) I get this error: UnicodeEncodeError: ‘ascii’ codec can’t encode character u’xc7′ in …

Total answers: 2

Python string argument without an encoding

Python string argument without an encoding Question: Am trying to a run this piece of code, and it keeps giving an error saying “String argument without an encoding” ota_packet = ota_packet.encode(‘utf-8’) + bytearray(content[current_pos:(final_pos)]) + ”.encode(‘utf-8′) Any help? Asked By: lonely || Source Answers: You are passing in a string object to a bytearray(): bytearray(content[current_pos:(final_pos)]) You’ll …

Total answers: 2

Python 3: os.walk() file paths UnicodeEncodeError: 'utf-8' codec can't encode: surrogates not allowed

Python 3: os.walk() file paths UnicodeEncodeError: 'utf-8' codec can't encode: surrogates not allowed Question: This code: for root, dirs, files in os.walk(‘.’): print(root) Gives me this error: UnicodeEncodeError: ‘utf-8’ codec can’t encode character ‘udcc3’ in position 27: surrogates not allowed How do I walk through a file tree without getting toxic strings like this? Asked …

Total answers: 4

Correctly reading text from Windows-1252(cp1252) file in python

Correctly reading text from Windows-1252(cp1252) file in python Question: so okay, as the title suggests the problem I have is with correctly reading input from a windows-1252 encoded file in python and inserting said input into SQLAlchemy-MySql table. The current system setup: Windows 7 VM with “Roger Access Control System” which outputs the file; Ubuntu …

Total answers: 3

Removing unicode u2026 like characters in a string in python2.7

Removing unicode u2026 like characters in a string in python2.7 Question: I have a string in python2.7 like this, This is some u03c0 text that has to be cleanedu2026! itu0027s annoying! How do i convert it to this, This is some text that has to be cleaned! its annoying! Asked By: Sandeep Raju Prabhakar || …

Total answers: 1

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

UnicodeDecodeError: 'utf8' codec can't decode byte 0x9c Question: I have a socket server that is supposed to receive UTF-8 valid characters from clients. The problem is some clients (mainly hackers) are sending all the wrong kind of data over it. I can easily distinguish the genuine client, but I am logging to files all the …

Total answers: 12

Python: Traceback codecs.charmap_decode(input,self.errors,decoding_table)[0]

Python: Traceback codecs.charmap_decode(input,self.errors,decoding_table)[0] Question: Following is sample code, aim is just to merges text files from give folder and it’s sub folder. i am getting Traceback occasionally so not sure where to look. also need some help to enhance the code to prevent blank line being merge & to display no lines in merged/master file. …

Total answers: 3