UnicodeDecodeError read string in CSV

I have a problem reading some characters in python.

I have a csv file in UTF-8 format and I read, but when the script read:

Preußen Münster-Kaiserslautern II

I get this error:

Traceback (most recent call last):
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/webapp/__init__.py", line 515, in __call__
    handler.get (* groups)
  File "/Users/fermin/project/gae/cuotastats/controllers/controllers.py", line 50, in get
    f.name = unicode (row [1])
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 4: ordinal not in range (128)

I tried using Unicode functions and converting a string to Unicode, but I did not find a solution. I tried to use sys.setdefaultencoding('utf8'), but that also does not work.

+3
source share
1 answer

Try the generator unicode_csv_reader()described in csv docs .

+7
source

Source: https://habr.com/ru/post/1790499/


All Articles