称呼Grafana API返回401未授权

问题描述 投票:0回答:0

在Grafana设置中,我添加了一个API键并将其设置为管理员。我尝试使用卷曲,失眠(如Postman)和Python调用API。 (替换API键和Grafana URL值) Curl:

curl -k -H "Authorization: Bearer <apikey>" https://<grafanaurl>/api/dashboards/home

response:

curl: (6) Could not resolve host: GET <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>401 Unauthorized</title> </head><body> <h1>Unauthorized</h1> <p>This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.</p> </body></html>

python:
import json
import requests

server= "https:<grafanaurl>"
url = server + "/api/dashboards/home"
headers = {
    "Authorization": "Bearer <apikey>",
    "Accept": "application/json",
    "Content-Type": "application/json"
    }
r = requests.request("GET", url, headers=headers, verify=False)
print(r)
# print(r.json())

response:

<Response [401]>

Insomnia给出了与curl相同的错误消息。

我做错了什么?我的组织使用LDAP身份验证将我们自动登录到Grafana上 - 这是为什么这不起作用的原因吗?如果是这样,我将如何处理?我希望能够从应用程序中调用Grafana API。
	
try这个

r = requests.get(url, headers=headers, verify=False)
这为我工作

python curl ldap grafana
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.