首页 > 解决方案 > 当我运行获取请求时,我不断收到 AttributeError: 'set' object has no attribute 'items'?

问题描述

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

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

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

我希望收到一个包含有关该 repos webhook 信息的 JSON,但会收到该错误。

标签: pythonpython-requests

解决方案


你忘了用逗号"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)

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


推荐阅读