title: Python to C++ Character encoding
body: <p>I have a C++ program that uses the Python C/API to call Python scripts for DB info, but the data received is not encoded in the right way. This is in France, so my data has accents and other non-English characters.</p>
  
  <p>In a python terminal with the sys.defaultencoding set to "utf-8", an example: </p>
  
  <pre><code>    &gt;&gt;&gt; robin = 'testé'
      &gt;&gt;&gt; robin
      'test\x82'
      &gt;&gt;&gt; print robin
      testé
      &gt;&gt;&gt; str(robin)
      'test\x82'
  </code></pre>
  
  <p>If I call:</p>
  
  <pre><code>    PyString_AsString(PyObject_Repr(PyObject_GetAttrString(/*PyObject of my Py_Init*/, "robin")));
  </code></pre>
  
  <p>I get a char* filled with the folowing: <em>test\x82</em></p>
  
  <p>And creating a <em>string</em> or <em>wstring</em> from that yields the same result. </p>
  
  <p>I would like to be able to create a string that says <em>"testé"</em>, and I'm guessing that starts with being able to output the variable correctly in the python terminal, as in:</p>
  
  <pre><code>    &gt;&gt;&gt; robin = 'testé'
      &gt;&gt;&gt; robin
      'testé'
  </code></pre>
  
  <p>I tried encode() decode(), sys.setdefaultencoding, sys.stdout.encoding, and even some force_text and force_bytes from Django. Nothing seems to be able to get me a standard C++ string with my actual characters in it. Any help would be greatly appreciated. </p>
  
  <p>FYI - Python 2.7, Windows 8 x64, VS2012 and C++9</p>
  
  <p><strong>EDIT to answer to comments:</strong></p>
  
  <pre><code>    &gt;&gt;&gt; import sys
      &gt;&gt;&gt; reload(sys)
      &lt;module 'sys' (built-in)&gt;
      &gt;&gt;&gt; sys.setdefaultencoding('utf-8')
      &gt;&gt;&gt; sys.getdefaultencoding()
      'utf-8'
      &gt;&gt;&gt; robin = 'testé'
      &gt;&gt;&gt; robin
      'test\x82'
      &gt;&gt;&gt; print robin
      testé
  </code></pre>
  
  <p>I just want whatever 'print' does to display the information correctly...</p>