Convert CURL Post to Python Requests Failing
<p>I am unable to successfully convert and execute a curl post command to python code.</p>

<p>curl command</p>

<pre><code>curl -X POST -H "Content-Type:application/json; charset=UTF-8" -d '{"name":joe, "type":22, "summary":"Test"}' http://url
</code></pre>

<p>Converted code</p>

<pre><code>import requests
import json 

url="http://url"
data = {"name":joe, "type":22, "summary":"Test"}
headers = {'Content-type': "application/json; charset=utf8"}
response  = requests.post (url, data=json.dumps(data), headers=headers)
print response.text
print response.headers
</code></pre>

<p>I get no response in return, when I execute it manually from the shell it works fine, but when I execute the code, nothing happens, I don't see errors or anything. </p>

<p>If you are using one of the latest versions of requests:
Try using the 'json' kwarg (no need to convert to json explicitly) instead of the 'data' kwarg:</p>

<pre><code>response = requests.post(url, json=data, headers=headers)
</code></pre>

<p>Note: Also, this way you can omit the 'Content-type' header.</p>

python curl server python-requests