【问题标题】:Python Curl request with access token not working带有访问令牌的 Python Curl 请求不起作用
【发布时间】:2019-11-30 20:27:06
【问题描述】:

我在使用 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 内容

【问题讨论】:

    标签: python authentication curl python-requests access-token


    【解决方案1】:

    curl 使用的是Post,而你使用的是get,问题出在:

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

    【讨论】:

      【解决方案2】:

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

      所以只需更改您的 Python 代码 从requests.getrequests.post

      【讨论】:

        猜你喜欢
        • 2017-12-30
        • 2016-05-23
        • 2021-09-01
        • 2019-06-04
        • 2019-03-23
        • 1970-01-01
        • 1970-01-01
        • 2020-01-15
        • 1970-01-01
        相关资源
        最近更新 更多