Reputation: 730
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?
Upvotes: 0
Views: 69
Reputation: 86
Can you try this and see if it works?
import requests
import json
url = "https://api.sensorpush.com/api/v1/oauth/authorize"
headers = {'Content-Type':'application/json', 'accept':'application/json'}
data = { "email": "[email protected]", "password": "abc123" }
data = json.dumps(data)
r = requests.post(url, data=data, headers=headers)
print(r.json())
Upvotes: 2