Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 仪表板缓冲的Api键_Python_Http Status Code 401_Api Key_Dashing - Fatal编程技术网

Python 仪表板缓冲的Api键

Python 仪表板缓冲的Api键,python,http-status-code-401,api-key,dashing,Python,Http Status Code 401,Api Key,Dashing,我正在使用dashing.io仪表板,我想用python中的requests库发出post请求,将数据放入小部件中 但它一直向我发回401错误和无效的API密钥。我不明白为什么,也没有真正了解auth_令牌和api密钥之间的区别 这是我的密码: import json import requests dashboard_url = "http://localhost:3030" widget_id = 'my_widget_id' widget_url = dashboard_url +

我正在使用dashing.io仪表板,我想用python中的requests库发出post请求,将数据放入小部件中

但它一直向我发回401错误和无效的API密钥。我不明白为什么,也没有真正了解auth_令牌和api密钥之间的区别

这是我的密码:

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
我在config.ru中的代码身份验证令牌也是XYZ。
你们能帮我吗?

你们需要在有效载荷中包含密钥,而不是标题

data = {
    'name'       : 'thomas',
    'id'         : 'bonjour',
    'city'       : 'cerfontaine',
    'auth_token' : YOUR_AUTH_TOKEN_HERE
}

请参见我的Django示例

您没有发送正确的API密钥