2

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. 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. 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"}'

What might be the reason for this?

1 Answer 1

1

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. 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.

Sign up to request clarification or add additional context in comments.

1 Comment

That check you suggested definitely reduced the number of 403 errors, thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.