lundi 29 juin 2015

How to check for certain ANSI Hex code in a string python


So I'm getting an error when I parse data from an .csv file and insert the data into a database. The code from the excel file has some characters that aren't compatible for UTF8 encoding. I'm looking for a way to replace these characters so that I can insert it into the databases.

One example special character is 0x92 which is the double dash in microsoft documments. Here's the psuedocode I'm looking for

special_character = 0x92
if special_character in word:
    replace special_character with "" in word

here's the error I'm getting:

 [Mon Jun 29 13:26:35.423226 2015] [wsgi:error] [pid 12439:tid 
 140199602177792] [remote 10.0.2.2:188] DataError: (psycopg2.DataError) 
 invalid byte sequence for encoding "UTF8": 0x92

I know there has to be an issuing with the formatting, but I'm not sure what exactly to change


Aucun commentaire:

Enregistrer un commentaire