[英]Gitlab v4 api 403 forbidden error for project.variables.list(get_all=True)
I am using Gitlab v4 api to list a project's variables, while the code returns vars for some projects, it also returns 403 forbidden response for some other projects.我正在使用 Gitlab v4 api 列出项目的变量,而代码为某些项目返回 vars,它还为其他一些项目返回 403 禁止响应。 And the error is not very verbose so I'm confused what could be the possible reason.
而且错误不是很冗长,所以我很困惑可能是什么原因。 I'm using a group access token which has read api permissions on all projects within the group.
我正在使用一个组访问令牌,该令牌已读取组内所有项目的 api 权限。 Below is the piece of code:
下面是一段代码:
group = gl.groups.get(20, lazy=True)
group_projects = group.projects.list(include_subgroups=True, all=True)
for group_project in group_projects:
project = gl.projects.get(group_project.id)
project.variables.list(get_all=True)
error: b'{"message":"403 Forbidden"}'
错误:
b'{"message":"403 Forbidden"}'
What might be the reason for this?这可能是什么原因?
GitLab's API response isn't really clear, but projects that are archived, have an empty repository, or have the repository/CI feature disabled, will not have variables available. GitLab 的 API 响应不是很清楚,但已归档、具有空存储库或禁用存储库/CI 功能的项目将没有可用的变量。 You can guard against this by checking for those features in your loop:
您可以通过检查循环中的这些功能来防止这种情况:
if (
project.archived
or project.empty_repo
or project.repository_access_level == "disabled"
):
continue
Or something to that effect.或者类似的东西。 You can also check in the UI if the variable settings are actually visible.
如果变量设置实际可见,您还可以在 UI 中进行检查。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.