Csv file import - Error: Cannot create PyString with non-byte value

I was able to get a sample file (encoded in UTF-8) containing Chinese characters to decode in csv.DictReader with a little finagling:

import csv
from io import StringIO
from org.python.core.util import StringUtil

path = r"C:\Users\pgriffith\Downloads\IM Translation_Small.csv"

data = system.file.readFileAsBytes(path)
reader = csv.DictReader(StringIO(StringUtil.fromBytes(data)))

for row in reader:
	print {key: value.decode("utf-8") for key, value in row.items()}
2 Likes