当我运行 get 请求时,我不断收到 AttributeError: 'set' object has no attribute 'items'?

Wil*_*ill 6 python python-requests

当我尝试使用请求库执行获取请求时,我不断收到错误:“AttributeError:'set'对象没有属性'items'”。

下面显示了我已经尝试过的内容。

gethooks = "https://api.github.com/repos/ORGANIZATION/REPO/hooks"
response = requests.get(gethooks, headers={"Authorization: token GITHUBTOKEN"})
print(response)
Run Code Online (Sandbox Code Playgroud)

我希望收到包含有关该存储库 Webhooks 的信息的 JSON,但收到了该错误。

小智 9

你忘记了逗号"token GITHUBTOKEN"

import requests
gethooks= "https://api.github.com/repos/ORGANIZATION/REPO/hooks"
headers={"Authorization": "token GITHUBTOKEN"}
response = requests.get(gethook, headers=headers)
print(response)
Run Code Online (Sandbox Code Playgroud)

你应该试试。它会给你结果


小智 6

尝试:

gethooks = "https://api.github.com/repos/ORGANIZATION/REPO/hooks"
response = requests.get(gethooks, headers={'Authorization': 'token GITHUBTOKEN'})
print(response)
Run Code Online (Sandbox Code Playgroud)

您应该使用字典作为标题。