title: GAE Python - CSV Writer gives ascii codec error
body: <p>I have a Google App Engine app that stores data in a number of languages, like e.g. German and Russian. To do so, I need to store the strings as UTF-8, which luckily is done automatically since I use the webapp2.request handler. As a beginning programmer, this allowed me to avoid the complications of encoding and decoding the data. </p>
  
  <p>However now I am trying to write the contents to a CSV file, and it seems that for the csv.writer command, the encoding is necessary anyway. Now I am not sure if I should be decoding or encoding, but currently the error I get is following:</p>
  
  <pre><code>UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-9: ordinal not in range(128)
  </code></pre>
  
  <p>The code I am using is:</p>
  
  <pre><code>import csv, webapp2, codecs
  
  class AdminShopExport(webapp2.RequestHandler):
    def get(self):
      shops = Shop.all()
      shops.order('name')
      self.response.headers['Content-Type'] = 'application/csv'
      writer = csv.writer(self.response.out)
      writer.writerow(["id", "name", "domain", "category"])
      for shop in shops:
        writer.writerow([shop.keyname, shop.name, shop.url, shop.category])
  </code></pre>
  
  <p>Regarding the contents, the error is currently coming from a category which is given in Russian. However as said, any of these fields could contain a UTF-8 character. What would be the best way to handle this? Thanks for your help!</p>