将 python 模块请求与 Sitescout API 一起使用时的响应状态代码 400

Response status code 400 when using python module Requests with Sitescout API

我有一个客户端 ID 和客户端密码,我正在尝试通过遵循 Sitescout's api docs 来生成一个授权令牌。我正在使用 python 模块请求并返回 400 状态代码,也就是格式错误的请求,但我似乎无法弄清楚原因。

我的代码:

import requests

url = "https://api.sitescout.com/oauth/token"
headers = { 
            "Host": "api.sitescout.com",
            "Authorization": "Basic YmVldGhvdmVuOmxldG1laW4=",
            "Content-Type": "application/x-www-form-urlencoded",
            "Accept": "application/json",
            "Content-Length": "41"
        }

# Do the HTTP request
response = requests.post(url, headers=headers)

response.status_code

那是文档中提供的伪造的 base64 授权 header,所以这个片段 returns 是一个 401 错误,也就是未授权(我当然有自己的授权)。

谁能告诉我这是怎么回事?

已解决。我没有放grant_type=client_credentials,其中添加时,returns一个200.

文档说 "Optionally, you can add form parameter scope to indicate which scopes you are requesting access to; the scope values must be space delimited (e.g., STATS AUDIENCES)." 但“&scope=STATS”参数是可选的,而不是所有参数。这个例子让我很困惑。

现在我的代码是

...

params = {  "grant_type" : "client_credentials" }

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

...

有效。