'Unable to CURL POST in Python

The API instructions that I'm following state I should do the following:

# Log in with a valid username and password to receive an authorization code.
curl -X POST "https://api.sensorpush.com/api/v1/oauth/authorize" -H "accept: application/json" -H "Content-Type: application/json" -d @- <<BODY
{ "email": "[email protected]", "password": "abc123" }
BODY

I'm not very familiar with curl requests. After doing some research, I rewrote this in Python as:

import requests
from requests.structures import CaseInsensitiveDict

url = "https://api.sensorpush.com/api/v1/oauth/authorize"
headers = CaseInsensitiveDict()
headers["Content-Type"] = "applications/json"
data = "@- <<BODY { 'email': '[email protected]', 'password': 'abc123' } BODY"

resp = requests.post(url, headers=headers, data=data)

print(resp.status_code)

I expected to receive an authorization code, but all it returns is "412" (with the correct email and password inserted). This error code tells me access was denied, so I'm wondering what was incorrect about my Python code?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source