UnicodeDecodeError: 'ascii' codec can't decode byte with reading CSV
<p>Trying to read from a CSV file and write the data into an XML file. I am encountering:</p>

<pre><code>UnicodeDecodeError: 'ascii' codec can't decode byte 0x8a in position 87: ordinal not in range(128)
</code></pre>

<p>My question is, what is the best way to ignore this kind of error and continue processing the data set. After reading other similar questions, I did add: <code># -*- coding: utf-8 -*-</code> to my file but it didn't help</p>

<p>You can try opening csv with codecs:</p>

<pre><code>import codecs
codecs.open(file_name, 'r', 'utf8')
</code></pre>

<p>Given that each line will contain '\n' string you will need to apply <strong>line.rstrip()</strong> when looping trough lines.</p>

<p>Note: Please don't try to convert values to str as you will encounter another error there.</p>

python xml python-2.7 csv ascii