I'm working with the dashing.io dashboard and I want to make a post request with the requests lib in python to put data in a widget.
But it keeps sending me back a 401 error and an Invalid API Key. I don't understand why and don't really get the difference between the auth_token and the api key.
Here is my code:
import json
import requests
dashboard_url = "http://localhost:3030"
widget_id = 'my_widget_id'
widget_url = dashboard_url + '/widgets/my_widget_id'
data = {'name' : 'thomas','id' : 'bonjour','city' : 'cerfontaine'}
data = json.dumps(data)
headers ={'Content-Type':'application/json', 'Accept':'text/plain',
'Authorization':'XYZ'}
try:
r = requests.post(widget_url, data, headers=headers)
print r.status_code
print r.json()
print r.text
except:
r = requests.post(widget_url, data, headers=headers)
print 'Dashing update failed'
print r.text
My code auth_token in config.ru is XYZ too. Can you guys help me ?
You need to include the key in your payload, not the header
data = {
'name' : 'thomas',
'id' : 'bonjour',
'city' : 'cerfontaine',
'auth_token' : YOUR_AUTH_TOKEN_HERE
}
See my Django example here