How to bypass UnicodeDecodeError in python module, pytds - python

The pytds module throws the following error when retrieving a certain record from my MSSQL database:
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 97: character maps to <undefined>
I've found other solutions for fixing this using the open() command in Python, but none for the pytds module.
Are there any ways to bypass this error or handle it on a per record basis?

Related

charmap codec characted encoding error

I have a thai address stored in my table and using a simple query I am getting output as
u'35/1-2 8 \u0e16\u0e19\u0e19\u0e23\u0e31\u0e15\u0e19\u0e32\u0e18\u0e34\u0e40\u0e1a\u0e28\u0e23\u0e4c \u0e1a\u0e32\u0e07\u0e01\u0e23\u0e30\u0e2a\u0e2d \u0e40\u0e21\u0e37\u0e2d\u0e07\u0e19\u0e19\u0e17\u0e1a\u0e38\u0e23\u0e35 \u0e19\u0e19\u0e17\u0e1a\u0e38\u0e23\u0e35'
I tried to decode it by following command:
QtGui.QTableWidgetItem(data[i][j].decode('utf-8'))
But I am getting this error
data[i][j] Error btnManualSearch 'charmap' codec can't encode characters in position 10-24: character maps to <undefined>

Fix unicode encoding error writing from bigquery to a csv in python

I am trying to use the ML Workbench module in datalab.
When running
%%ml analyze --cloud
output: gs://bucket/pathcontinued
data: model_3pcnt
features:
I get an error like.
File "pandas/_libs/lib.pyx", line 1052, in pandas._libs.lib.write_csv_rows
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe7' in position 4: ordinal not in range(128)
I'm not sure how there can possibly be an encoding error reading directly from a bigquery table into a csv.
Is there a workaround or reason writing to a csv is not working?

Python script utf-8 issue

I try to use this python text-to-speech converter to convert Greek into mp3.
Git says utf-8 is supported but when I try to translate text like "Γεια σου" it throws an error as shown below:
What I type on cmd: gtts-cli.py "Γεια σου" -l el -o hi.mp3
What I get:
'ascii' codec can't decode byte 0xf4 in position 0: ordinal not in
range(128)
Any ideas?
Update:
I added utf-8 support as shown below. I even updated to python3. Still getting a similar error...
'utf8' codec can't decode byte 0xc3 in position 0: invalid continuation byte
What I added:
text = args.text.decode('utf-8')
Any ideas?
There is related open issue in this project, please take a look.
Looks like the fix was created by the somebody already though, but it is still not merged.

python pyinstaller UnicodeDecodeError cp949

I get unicodedecodeerror when I try to install pyinstaller.
The error message reades:
UnicodeDecodeError: 'cp949' codec can't decode byte 0xe2 in position 208687: illegal multibyte sequence
When I google this error, it looks like an error with codec to read the file.
Tried some of the solutions found online but didn't work.
How can I fix this?
I think in your code have function to print some data with the codec which the window shell does not support display. Remove them and try again(I cannot comment because not enough rep so i wrote here)

load .json into python; UnicodeDecodeError

I am trying to load a json file into python with no success. I have been googling a solution for the past few hours and just cannot seem to get it to load. I have tried to load it using the same json.load('filename') function that has worked for everyone. I keep getting :
"UnicodeDecodeError: 'utf8' codec can't decode byte 0xc2 in postion 124: invalid continuation byte"
Here is the code I am using
import json
json_data = open('myfile.json')
for line in json_data:
data = json.loads(line) <--I get an error at this.
Here is a sample line from my file
{"topic":"security","question":"Putting the Biba-LaPadula Mandatory Access Control Methods to Practise?","excerpt":"Text books on database systems always refer to the two Mandatory Access Control models; Biba for the Integrity objective and Bell-LaPadula for the Secrecy or Confidentiality objective.\n\nText books ...\r\n "}
What is my error if this seems to have worked for everyone in every example I have googled?
Have you tried:
json.loads(line.decode("utf-8"))
Similar question asked here: UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2
Edit:
If the above does not work,
json.loads(line.decode("utf-8","ignore"))
will.

Categories

Resources