简体   繁体   English

Gitlab v4 api 403 project.variables.list 禁止错误(get_all=True)

[英]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.

相关问题 如何通过 GitLab V4 api 列出 gitlab 项目中的所有项目变量 - How to list all the project variables in a gitlab project via GitLab V4 api GitLab:将项目转移到组显示403禁止错误 - GitLab: Transferring project to Group shows 403 Forbidden error Gitlab api v4 在使用命名空间/项目名称而不是 id 时在项目搜索中返回 404 - Gitlab api v4 returns 404 on project search when using namespace/projectname instead of id 通过 python 访问 API 得到一个奇怪的错误 403 禁止 - Getting a strange error 403 forbidden for accessing an API through python 为什么我只在 SendGrid Api v3 上的某些 api 上收到 403 错误? - Why do I get 403 error only on certain apis on SendGrid Api v3? gitlab 的本地实例不响应位于“/gitlab/doc/api/v4”中的 API 文档中的 REST 调用 - Local instance of gitlab does not respond to REST-calls from the API documentation located in "/gitlab/doc/api/v4" gitlab runner 请求的URL 返回error: 403 - gitlab runner The requested URL returned error: 403 Google Analytics API v4 最大结果 - Google analytics API v4 max results GiLab - 是否可以通过 GitLab API 获得 4 天前执行的项目的作业 ID - GiLab - is it possible to get job id of the project which was executed 4 days ago through GitLab API 无法使用 HTTP 在本地测试 Sendgrid 错误 403:禁止 - Unable to test Sendgrid locally with HTTP Error 403: Forbidden
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM