![]() You'd want to use codecs.open() instead, which returns a file object that will encode unicode values to UTF-8 for you. If you instead build up unicode values instead, you would indeed have to encode those to be writable to a file. ![]() Just write your data directly to the file, there is no need to encode already-encoded data. UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128) > data.encode('utf8') # Try to *re*-encode it > data = data.encode('utf8') # encoded to UTF-8 That is what is failing here: > data = u'Ã' # Unicode data When you try to do that, Python will first try to decode it to unicode before it can encode it back to UTF-8. You don't need to encode data that is already encoded. Sql = mdb.connect('localhost','admin','*******','music_vibration')Ĭ.execute('SELECT COUNT(id) AS nbr FROM artistes WHERE nom="'+artiste+'"')Ĭ.execute('INSERT INTO artistes(nom,status,path) VALUES("'+artiste+'",99,"'+artiste+'/")'.encode('utf8')Īnd artiste who are nicely displayed in the file writes bad into the BDD. My function looks like this : #!/usr/bin/python My MySQL database is in utf8, or seems to be SQL query SHOW variables LIKE 'char%' returns me only utf8 or binary. After creating this file, I read it and I write it into MySQL.īut I dont understand why, but I got problem with encoding. ![]() I see, in my file, the accent are nicely written. #lot of operations & building indexSTR the string who matterįindex=open('config/index/music_vibration_'+date+'.index','a')įindex.write(toUtf8(indexSTR)) #this bugs!Īnd when I execute, here is the answer : UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 2171: ordinal not in range(128) My script begin with this : #!/usr/bin/python I read some informations on the internet and i did like this. I want that python always use string as UTF-8. I want to keep everything in UTF-8 because I will save it in MySQL after.įor now, in MySQL, which is in UTF-8, I got some problem with some characters (like é or è - I'am French). This string got lot of data, coming from the arborescence and filenames of a directory.Īccording to convmv, all my arborescence is in UTF-8. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |