title: Convert a CURL to Python - HTTPS POST
body: <p>I'm trying to POST some data to an HTTPS server. It requires a very particular set of headers.  I'm able to complete the request, but I'm <em>unable</em> to do so in Python.</p>
  
  <p>The curl:</p>
  
  <pre><code>curl -i 
  -H "Authorization: Basic a2V5OnNlY3JldA==" 
  -H "Content-Type: application/x-www-form-urlencoded" 
  -H "Content-Length: 99" 
  -H "User-Agent: Dalvik/2.1.0 (Linux; U; Android 5.1.1; Nexus 6 Build/LMY48Y)" 
  -H "Host: test.example.com" 
  -H "Connection: Keep-Alive" 
  -H "Content-type: application/json" 
  -d "grant_type=password&amp;username=me%40example.com&amp;password=abcd*1234&amp;scope=scope1_services+scope1_data" 
  "https://test.example.com/login/get/token/"
  </code></pre>
  
  <p>The Python is</p>
  
  <pre><code>import httplib, urllib
  host = "test.example.com"
  url = "/login/get/token/"
  
  params = urllib.urlencode({"grant_type":"password", "username":"me@example.com", "password":"abcd*1234", "scope":"scope1_services+scope1_data" })
  
  headers = {"Authorization": "Basic a2V5OnNlY3JldA==", "Content-type": "application/x-www-form-urlencoded", "Content-Length":"99", "User-Agent":"Dalvik/2.1.0 (Linux; U; Android 5.1.1; Nexus 6 Build/LMY48Y)", "Host":host, "Connection": "Keep-Alive",  "Content-type":"application/json"}
  
  conn = httplib.HTTPSConnection(host)
  conn.request("POST", url, params, headers)
  
  response = conn.getresponse()
  print response.status, response.reason
  </code></pre>
  
  <p>I just end up with <code>400 Bad Request</code> and the error message
  <code>
  {
     "error":"unsupported_grant_type",
     "error_description":"The authorization grant type is not supported by the authorization server."
  }</code></p>
  
  <p>As far as I can tell, everything should be the same.</p>
  
  <p>I've tried manually encoding the POST payload as <code>params="grant_type=password&amp;user...</code> but I still get the same error.</p>
  
  <p>Any idea what incredibly obvious thing I'm missing?</p>