title: Python Requests encoding POST data
body: <p>Version: Python 2.7.3</p>
  
  <p>Other libraries: Python-Requests 1.2.3, jinja2 (2.6)</p>
  
  <p>I have a script that submits data to a forum and the problem is that non-ascii characters appear as garbage. For instance a name like André Téchiné comes out as AndrÃ© TÃ©chinÃ©.</p>
  
  <p>Here's how the data is submitted:</p>
  
  <p>1) Data is initially loaded from a UTF-8 encoded CSV file like so:</p>
  
  <pre><code>entries = []
  with codecs.open(filename, 'r', 'utf-8') as f:
      for row in unicode_csv_reader(f.readlines()[1:]):
          entries.append(dict(zip(csv_header, row)))
  </code></pre>
  
  <p>unicode_csv_reader is from the bottom of Python CSV documentation page: <a href="http://docs.python.org/2/library/csv.html">http://docs.python.org/2/library/csv.html</a></p>
  
  <p>When I type the entries name in the interpreter, I see the name as <code>u'Andr\xe9 T\xe9chin\xe9'</code>.</p>
  
  <p>2) Next I render the data through jinja2:</p>
  
  <pre><code>tpl = tpl_env.get_template(u'forumpost.html')
  rendered = tpl.render(entries=entries)
  </code></pre>
  
  <p>When I type the name rendered in the interpreter I see again the same: <code>u'Andr\xe9 T\xe9chin\xe9'</code></p>
  
  <p>Now, if I write the rendered variable to a filename like this, it displays correctly:</p>
  
  <pre><code>with codecs.open('out.txt', 'a', 'utf-8') as f:
      f.write(rendered)
  </code></pre>
  
  <p>But I must send it to the forum:</p>
  
  <p>3) In the POST request code I have:</p>
  
  <pre><code>params = {u'post': rendered}
  headers = {u'content-type': u'application/x-www-form-urlencoded'}
  session.post(posturl, data=params, headers=headers, cookies=session.cookies)
  </code></pre>
  
  <p>session is a Requests session.</p>
  
  <p>And the name is displayed broken in the forum post. I have tried the following:</p>
  
  <ul>
  <li>Leave out headers</li>
  <li>Encode rendered as rendered.encode('utf-8') (same result)</li>
  <li>rendered = urllib.quote_plus(rendered) (comes out as all %XY)</li>
  </ul>
  
  <p>If I type rendered.encode('utf-8') I see the following:</p>
  
  <pre><code>'Andr\xc3\xa9 T\xc3\xa9chin\xc3\xa9'
  </code></pre>
  
  <p>How could I fix the issue? Thanks.</p>