title: How to send a HTTP POST with Python 2.7
body: <p>I'm trying to send a HTTP POST request with Python. I can get it to work with 3.0, but I couldn't find a good example on 2.7.</p>
  
  <pre><code>hdr = {"content-type": "application/json"}
  payload= ("&lt;html&gt;&lt;body&gt;&lt;h1&gt;Sorry it's not Friday yet&lt;/h1&gt; &lt;/body&gt;&lt;/html&gt;")
  r = requests.post("http://my-url/api/Html", json={"HTML": payload})
  
  with open ('c:/temp/a.pdf', 'wb') as f:
      b64str = json.loads(r.text)['BinaryData']  #base 64 string is in BinaryData attr
      binStr = binascii.a2b_base64(b64str)  #convert base64 string to binary
      f.write(binStr)
  </code></pre>
  
  <p>The api takes a json in this format:</p>
  
  <pre><code>{
    HTML : "a html string"
  }
  </code></pre>
  
  <p>and returns a json in this format:</p>
  
  <pre><code>{
      BinaryData: 'base64 encoded string'      
  }
  </code></pre>