2

I am using Google Cloud Endpoints with python. I am trying to fetch data from database what it is showing

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 14: ordinal not in range(128) error.

The field for which I am getting error is varchar with

"BTTR – oct 01 2014 10:00 AM ESt
Primary issue – Want to activate the kaspersky 
Plan Sold – NA
Any commitment –Call back 
Transferred to tech – NA
Session ID –222479342 
Transaction ID (Order ID) –NA
PDF push on sale call –Na" data. Please help.
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
Sunil Garg
  • 14,608
  • 25
  • 132
  • 189

2 Answers2

2

This code contains accents. Accents are not in ascii but in UTF-8

My thoughts are that your DB is in utf8, but your python encoding is set on ascii. You should either set your python idle (if used), your shell (if your trying to print), and your python script to UTF8.

Or convert your code using Unicode data

def remove_accents(input_str):
    nkfd_form = unicodedata.normalize('NFKD', input_str)
    only_ascii = nkfd_form.encode('ASCII', 'ignore')
    return only_ascii
0

I solved this by using

decode(encoding='unicode-escape',errors='strict')
Sunil Garg
  • 14,608
  • 25
  • 132
  • 189