繁体   English   中英

具有访问令牌的Python Curl请求不起作用

[英]Python Curl request with access token not working

我正在使用curl在API查询下面运行,我正在获取json响应。

curl -X POST   -H 'Content-Type: application/json'   -H 'X-Metabase-Session: sdfeffff-sdfdf-ffff-ffff-fffffffff'   https://dash.test.sh/api/card/140/query/json

但是当我尝试使用python请求运行相同的查询时,我得到了响应

"API endpoint does not exist."

以下是我正在尝试的python代码

import requests

url = 'https://dash.test.sh/api/card/140/query/json'
header = {
   'X-Metabase-Session': 'sdfeffff-sdfdf-ffff-ffff-fffffffff'
}

response = requests.get(url, headers=header)

print (response.text)

我希望实际的JSON内容

curl正在使用Post而您正在使用get ,问题就在这里:

response = requests.post(url, headers=header)

使用curl,您正在执行POST请求,但是在Python中,您正在调用相同API的GET方法。 可能,该API不存在GET方法。

因此,只需将您的Python代码从requests.get更改为requests.post

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM