title: Double-decoding unicode in python
body: <p>I am working against an application that seems keen on returning, what I believe to be, double UTF-8 encoded strings.</p>
  
  <p>I send the string <code>u'XüYß'</code> encoded using UTF-8, thus becoming <code>X\u00fcY\u00df</code> (equal to <code>X\xc3\xbcY\xc3\x9f</code>).</p>
  
  <p>The server <em>should</em> simply echo what I sent it, yet returns the following: <code>X\xc3\x83\xc2\xbcY\xc3\x83\xc2\x9f</code> (should be <code>X\xc3\xbcY\xc3\x9f</code>). If I decode it using <code>str.decode('utf-8')</code> becomes <code>u'X\xc3\xbcY\xc3\x9f'</code>, which looks like a ... unicode-string, containing the original string encoded using UTF-8.</p>
  
  <p>But Python won't let me decode a unicode string without re-encoding it first - which fails for some reason, that escapes me:</p>
  
  <pre><code>&gt;&gt;&gt; ret = 'X\xc3\x83\xc2\xbcY\xc3\x83\xc2\x9f'.decode('utf-8')
  &gt;&gt;&gt; ret
  u'X\xc3\xbcY\xc3\x9f'
  &gt;&gt;&gt; ret.decode('utf-8')
  # Throws UnicodeEncodeError: 'ascii' codec can't encode ...
  </code></pre>
  
  <p>How do I persuade Python to re-decode the string? - and/or is there any (practical) way of debugging what's actually in the strings, without passing it though all the implicit conversion <code>print</code> uses? </p>
  
  <p>(And yes, I have reported this behaviour with the developers of the server-side.)</p>