0

I'm trying to read a csv file file and keep getting the following error. Can anyone point me in the right direction to resolve this error?

import csv
with open('apple.csv') as csvfile:
    reader = csv.reader(csvfile)
    for row in reader:
        print("1")

Here is the output:

Traceback (most recent call last):
  File "/Users/arch/Desktop/ark/ark.py", line 4, in <module>
    for row in reader:
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 263: ordinal not in range(128)
  • You need to give your file an encoding; try `with open('apple.csv', encoding='utf8') as csvfile:` – Burhan Khalid Apr 20 '17 at 03:36
  • https://stackoverflow.com/questions/42671585/download-file-from-django-project-root-using-a-button – Tiago Martins Peres Apr 20 '17 at 03:38
  • Thanks. It turned out it was latin-1 encoding. – Arch Stanton Apr 20 '17 at 03:59
  • Possible duplicate of [UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 20: ordinal not in range(128)](http://stackoverflow.com/questions/9942594/unicodeencodeerror-ascii-codec-cant-encode-character-u-xa0-in-position-20) – Mani Apr 20 '17 at 04:33

0 Answers0