title: Python Unicode CSV export (using Django)
body: <p>I'm using a Django app to export a string to a CSV file.  The string is a message that was submitted through a front end form.  However, I've been getting this error when a unicode single quote is provided in the input.  </p>
  
  <pre><code>UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' 
    in position 200: ordinal not in range(128)
  </code></pre>
  
  <p>I've been trying to convert the unicode to ascii using the code below, but still get a similar error. </p>
  
  <pre><code>UnicodeEncodeError: 'ascii' codec can't encode characters in 
  position 0-9: ordinal not in range(128)
  </code></pre>
  
  <p>I've sifted through dozens of websites and learned a lot about unicode, however, I'm still not able to convert this unicode to ascii.  I don't care if the algorithm removes the unicode characters.  The commented lines indicate some various options I've tried, but the error persists.  </p>
  
  <pre><code>import csv
  import unicodedata
  
  ...
  
  #message = unicode( unicodedata.normalize(
  #                            'NFKD',contact.message).encode('ascii','ignore'))
  #dmessage = (contact.message).encode('utf-8','ignore')
  #dmessage = contact.message.decode("utf-8")
  #dmessage = "%s" % dmessage
  dmessage = contact.message
  
  csv_writer.writerow([
          dmessage,
  ])
  </code></pre>
  
  <p>Does anyone have any advice in removing unicode characters to I can export them to CSV?  This seemingly easy problem has kept my head spinning.  Any help is much appreciated.
  Thanks,
  Joe</p>