title: python: HTTP PUT with unencoded binary data
body: <p>I cannot for the life of me figure out how to perform an HTTP PUT request with verbatim binary data in Python 2.7 with the standard Python libraries.</p>
  
  <p>I thought I could do it with urllib2, but <a href="https://stackoverflow.com/questions/7983303/python-http-put-with-binary-data">that fails</a> because <a href="http://docs.python.org/library/urllib2.html#urllib2.Request" rel="nofollow noreferrer"><code>urllib2.Request</code></a> expects its data in <code>application/x-www-form-urlencoded</code> format. I do not want to encode the binary data, I just want to transmit it verbatim, after the headers that include </p>
  
  <pre><code>Content-Type: application/octet-stream
  Content-Length: (whatever my binary data length is)
  </code></pre>
  
  <p>This seems so simple, but I keep going round in circles and can't seem to figure out how. </p>
  
  <p>How can I do this? (aside from open up a raw binary socket and write to it)</p>