我正在尝试使用 Grafana 的后端 API 创建一个仪表板。我首先测试我的 API 令牌是否是使用 GET 设置的,并成功获得返回码 200(如下所示)。然后,我尝试使用 POST 创建一个简单的仪表板,但我不断收到返回码 400。我很确定它与我尝试发送的有效负载有关,但我一直无法弄清楚。以下是我用于 JSON 格式的示例页面的链接。http://docs.grafana.org/reference/http_api/ http://docs.grafana.org/reference/http_api/
import requests
headers = {"Accept": "application/json","Content-Type": "application/json" ,"Authorization": "Bearer xxx"}
r = requests.get("http://www.localhost",headers=headers)
print(r.text)
print(r.status_code)
dashboard = {"id": None,
"title": "API_dashboard_test",
"tags": "[CL-5]",
"timezone": "browser",
"rows":"[{}]",
"schemaVersion": 6,
"version": 0
}
payload = {"dashboard": "%s" % dashboard}
url = "http://www.localhost/api/dashboards/db"
p = requests.post(url,headers=headers, data=payload)
print(p)
print(p.status_code)
print(p.text)
OUTPUT:
200
<Response [400]>
400
[{"classification":"DeserializationError","message":"invalid character 'd' looking for beginning of value"},{"fieldNames":["Dashboard"],"classification":"RequiredError","message":"Required"}]