I'm parsing a CSV as follows:
with open(args.csv, 'rU') as csvfile:
try:
reader = csv.DictReader(csvfile, dialect=csv.QUOTE_NONE)
for row in reader:
...
where args.csv
is the name of my file. One of the rows in my file is an e with two dots on top. My script breaks when it encounters this.
I get the following stack trace:
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 244, in dumps
return _default_encoder.encode(obj)
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 207, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 270, in iterencode
return _iterencode(o, 0)
and the following error:
UnicodeDecodeError: 'utf8' codec can't decode byte 0x91 in position 5: invalid start byte
FWIW, I'm running Python 2.7 and upgrading isn't an option (for a few reasons).
I'm pretty lost about how to fix this so any help is much appreciated.
Thanks!