title: How do I post non-ASCII characters using httplib when content-type is "application/xml"
body: <p>I've implemented a Pivotal Tracker API module in Python 2.7. The <a href="https://www.pivotaltracker.com/help/api?version=v3" rel="noreferrer">Pivotal Tracker API</a> expects POST data to be an XML document and "application/xml" to be the content type.</p>
  
  <p>My code uses urlib/httplib to post the document as shown:</p>
  
  <pre><code>    request = urllib2.Request(self.url, xml_request.toxml('utf-8') if xml_request else None, self.headers)
      obj = parse_xml(self.opener.open(request))
  </code></pre>
  
  <p>This yields an exception when the XML text contains non-ASCII characters:</p>
  
  <pre><code>File "/usr/lib/python2.7/httplib.py", line 951, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python2.7/httplib.py", line 809, in _send_output
    msg += message_body
  exceptions.UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 89: ordinal not in range(128)
  </code></pre>
  
  <p>As near as I can see, httplib._send_output is creating an ASCII string for the message payload, presumably because it expects the data to be URL encoded (application/x-www-form-urlencoded). It works fine with application/xml as long as only ASCII characters are used.</p>
  
  <p>Is there a straightforward way to post application/xml data containing non-ASCII characters or am I going to have to jump through hoops (e.g. using Twistd and a custom producer for the POST payload)?</p>