【问题标题】:Api key for dashing dashboarddashing仪表板的api键
【发布时间】:2014-10-02 15:07:49
【问题描述】:

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

但它不断向我发送 401 错误和无效的 API 密钥。我不明白为什么,也没有真正理解 auth_token 和 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 中的代码 auth_token 也是 XYZ。 你们能帮帮我吗?

【问题讨论】:

  • 您没有发送正确的 API 密钥

标签: python http-status-code-401 api-key dashing


【解决方案1】:

您需要在有效负载中包含密钥,而不是标题

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

查看我的 Django 示例here

【讨论】:

    猜你喜欢
    • 2014-06-01
    • 2016-08-21
    • 1970-01-01
    • 2014-05-02
    • 1970-01-01
    • 1970-01-01
    • 2022-11-03
    • 2019-05-22
    • 1970-01-01
    相关资源
    最近更新 更多