title: Python requests module, need to encode the body, why?
body: <p>I was struggling with sending a request to a web service using the requests module. I'm using Python 3.5.1-32 bit on Windows.</p>
  
  <p>Whenever I request something that contains, for example, a latin accented character such as "á" then I need to encode my string variable explicitly as utf-8. Can someone explain why I need to do this?</p>
  
  <p>Here is my code example:</p>
  
  <pre><code>import requests
  
  headers = { "content-type" : "text/xml;charset=UTF-8" }
  url = '....'
  body = 'á'
  requests.post(url, data=body, headers=headers)
  </code></pre>
  
  <p>This doesn't work, the server receives an escaped version of the character, but if I add this before the request:</p>
  
  <pre><code>body = body.encode(encoding='utf-8')
  </code></pre>
  
  <p>It works.</p>
  
  <p>Can somebody explain why this is necessary? My Python-Fu is such that it took me a good while to figure this out.</p>