Python: Json dumps escape quote
<p>There is a POST request which works perfectly when I pass the data as below:</p>

<pre><code>url = 'https://www.nnnow.com/api/product/details'

requests.post(url, data="{\"styleId\":\"BMHSUR2HTS\"}", headers=headers)
</code></pre>

<p>But when I use <code>json.dumps()</code> on a dictionary and send the response, I do not get the response (response code 504), using <code>headers={'Content-Type': 'application/json'}</code> . Have also tried json parameter of Post requests.</p>

<pre><code>requests.post(url, data=json.dumps({"styleId":"BMHSUR2HTS"}), headers={'content-type': 'application/json'})
</code></pre>

<p>Now, the data returned by <code>json.dumps({"styleId":"BMHSUR2HTS"})</code> and 
<code>"{\"styleId\":\"BMHSUR2HTS\"}"</code> is not the same.</p>

<p><code>json.dumps({"styleId":"BMHSUR2HTS"}) == "{\"styleId\":\"BMHSUR2HTS\"}"</code> gives <code>False</code> even though a print on both shows a similar string.</p>

<p>How can I get the same format as <code>"{\"styleId\":\"BMHSUR2HTS\"}"</code> from a dictionary <code>{"styleId":"BMHSUR2HTS"}</code> ?</p>

<p>If you print the <code>json.dumps({"styleId":"BMHSUR2HTS"})</code> it'll happen 2 things:
1. your output is a string (just try <code>type(json.dumps({"styleId":"BMHSUR2HTS"}))</code>);
2. if you pay attention the output will add a space between the json name and value: '{"styleId": "BMHSURT2HTS"}'.</p>

<p>Not sure how do you want to handle this, and in your entry code, but there are 2 main options to workaround this issue:
1. Replace the space on json.dumps output: <code>json.dumps({"styleId":"BMHSUR2HTS"}).replace(': ', ':')</code>
2. Convert all to json by using eval(): <code>eval(json.dumps({"styleId":"BMHSUR2HTS"}))</code> and <code>eval(YOUR_JSON_STRING)</code></p>

<p>I hope this helps you.</p>

python json