title: How can I decode this utf-8 string, picked on a random website and saved by the Django ORM, using Python?
body: <p>I parsed a file and saved its content in a database using Django. The website was 100% in English, so I naively assumed it would be ASCII all along, and saved the text happily as unicode.</p>
  
  <p>You guess the rest of the story :-)</p>
  
  <p>When I print, I get the usual encoding error:</p>
  
  <pre><code>UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 48: ordinal not in range(128)
  </code></pre>
  
  <p>A quick search tells me that u'\u2019' is the UTF-8 representation of <code>’</code>.</p>
  
  <p><code>repr(string)</code> displays me this:</p>
  
  <pre><code>"u'his son\\u2019s friend'"
  </code></pre>
  
  <p>Then of course I tried <code>django.utils.encoding.smart_str</code> and a more direct approach using string.encode('utf-8'), and I ended up with something printable. Unfortunatly, it prints  like this in my (linux UTF-8) terminal:</p>
  
  <pre><code>In [76]: repr(string.encode('utf-8'))
  Out[76]: "'his son\\xe2\\x80\\x99s friend '"
  
  In [77]: print string.encode('utf-8')
  his son�s friend
  </code></pre>
  
  <p>Not what I expected. I suspect I double encoded something or missed an important point. </p>
  
  <p>Of course the file original encoding is not pusblished with the file. I guess I could read the HTTP headers or ask the webmaster but since \u2019s looks like UTF-8, I assumed it was utf-8. I can be very wrong, tell me if I am.</p>
  
  <p>Solutions obviously appreciated, but a deep explanation on the cause and what to do to avoid this to happen again would be even more. I often get bitten with encoding, which shows that I still don't master completly the subject.</p>