相关疑难解决方法(0)

无法通过 Grafana API 导入 Grafana 仪表板

我想通过以下导入使用HTTP API的Grafana仪表盘Grafana

Grafana 版本:5.1.3 操作系统 -Windows 10

这是我试过的

curl --user admin:admin "http://localhost:3000/api/dashboards/db" -X POST -H "Content-Type:application/json;charset=UTF-8" --data-binary @c:/Users/Mahadev/Desktop/Dashboard.json
Run Code Online (Sandbox Code Playgroud)

这是我的python代码

import requests

headers = {
'Content-Type': 'application/json;charset=UTF-8',
}

data = open('C:/Users/Mahadev/Desktop/Dashboard.json', 'rb').read()
response = requests.post('http://admin:admin@localhost:3000/api/dashboards/db', headers=headers, data=data)
print (response.text)
Run Code Online (Sandbox Code Playgroud)

两者的输出是:

[{"fieldNames":["Dashboard"],"classification":"RequiredError","message":"Required"}]
Run Code Online (Sandbox Code Playgroud)

它在我的 json 负载中要求名为仪表板的根属性。任何人都可以建议我如何使用该属性以及我应该提供哪些数据。

如果有人想挖掘更多,这里有一些链接。

https://github.com/grafana/grafana/issues/8193
https://github.com/grafana/grafana/issues/2816
https://github.com/grafana/grafana/issues/8193
https://community.grafana.com/t/how-can-i-import-a-dashboard-from-a-json-file/669
https://github.com/grafana/grafana/issues/273
https://github.com/grafana/grafana/issues/5811
/sf/ask/2797767801/
/sf/ask/2796813281/#39954514
https://www.bountysource.com/issues/44431991-use-api-to-import-json-file-error
https://github.com/grafana/grafana/issues/7029
Run Code Online (Sandbox Code Playgroud)

python grafana

6
推荐指数
1
解决办法
4576
查看次数

POST请求适用于Postman,但不适用于Python

当我在邮递员中发出此POST请求时,我得到了数据。当我在Python 2.7(使用Jupyter笔记本)中执行此操作时,出现错误“无法解码JSON对象”。我在做什么错,如何使它正常工作?

import json
import requests
url = 'http://api.scb.se/OV0104/v1/doris/en/ssd/BE/BE0101/BE0101A/BefolkningNy'

headers={'content-type': 'application/json'}
payload = {  
"query": [
 {       
 "code": "ContentsCode",
  "selection": {        
    "filter": "item",         
    "values": [          
      "BE0101N1"         
    ]      
   }    
},    
{      
   "code": "Tid",
   "selection": {        
   "filter": "item",         
  "values": [           
   "2010",          
   "2011"         
   ]      
  }    
 },
 {      
  "code": "Region",
    "selection": {        
    "filter": "item",         
   "values": [           
   "01"         
   ]      
  }    
 }   
],  
"response": {    
  "format": "json"   
 }
}
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}

r = requests.post(url, data=payload)
print(r.text)
print(r.json())
Run Code Online (Sandbox Code Playgroud)

api的手册在这里,但是并没有太大帮助:

http://www.scb.se/zh_/About-us/Open-data-API/API-for-the-Statistical-Database-/

python json

2
推荐指数
1
解决办法
4725
查看次数

标签 统计

python ×2

grafana ×1

json ×1