title: UnicodeEncodeError: 'ascii' codec can't encode
body: <p>Ia have the following data container which is constantly being updated:</p>
  
  <pre><code>  data = []
          for val, track_id in zip(values,list(track_ids)):
              #below
              if val &lt; threshold:
                  #structure data as dictionary
                  pre_data = {"artist": sp.track(track_id)['artists'][0]['name'], "track":sp.track(track_id)['name'], "feature": filter_name, "value": val}
                  data.append(pre_data)
          #write to file
          with open('db/json/' + user + '_' + product + '_' + filter_name + '.json', 'w') as f:
              json.dump(data,f, ensure_ascii=False, indent=4, sort_keys=True)
  </code></pre>
  
  <p>but I am getting a lot of errors like this:</p>
  
  <p><code>json.dump(data,f, ensure_ascii=False, indent=4, sort_keys=True)
   File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 190, in dump
      fp.write(chunk)</code>
  <code>UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 6: ordinal not in range(128)</code></p>
  
  <p>Is there a way I can get rid of this encoding problem once and for all?</p>
  
  <p>I was told that this would do it:</p>
  
  <pre><code>import sys
  reload(sys)
  sys.setdefaultencoding('utf-8')
  </code></pre>
  
  <p>but many people do not recommend it.</p>
  
  <p>I use <code>python 2.7.10</code></p>
  
  <p>any clues?</p>