title: Django - how to stringify JSON object when passing it as payload to request.post()
body: <p>I have the following code in my Django view:</p>
  
  <pre><code>headers = {'Authorization': "key=AAAA7oE3Mj...",
                 'Content-type': 'application/json'}
  token  = "dJahuaU2p68:A..."
  payload = {"data": {}, "to": user_web_tokens}
  url = "https://..."
  r = requests.post(url, data=payload, headers=headers)
  </code></pre>
  
  <p>The problem is that the response terminates with 400 error with the error message being:</p>
  
  <blockquote>
    <p>JSON_PARSING_ERROR: Unexpected character (t) at position 0</p>
  </blockquote>
  
  <p>If I pass a string instead of JSON:</p>
  
  <p><code>payload = {"data": {}, "to": user_web_tokens}</code></p>
  
  <p>...I get a slightly different error:</p>
  
  <blockquote>
    <p>JSON_PARSING_ERROR: Unexpected character (u) at position 19.</p>
  </blockquote>
  
  <p>I have come across a post where they say that a json object should be stringified before being passed on as a payload. But I have no idea how to this in Django. Does it have something to with serialization ? Help me please !</p>