python-gitlab / python-gitlab

A python wrapper for the GitLab API.

Home Page:https://python-gitlab.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

creating group runner fails with 403

harridu opened this issue · comments

Description of the problem, including code/CLI snippet

Creating a group runner via

registration_token = ''glpat-bcK_xxxxxxxxxxxxxxxx"
tag_list = ["tag1", "tag2", "tag3"]
gl = gitlab.Gitlab.from_config('runners.gitlab.com')
gl.auth()
r = gl.runners.create({'runner_type': 'group_type', 'group_id': 123456, 'tag_list': tag_list, 'token': registration_token})
r.pprint()

fails with

gitlab.exceptions.GitlabHttpError: 403: 403 Forbidden - invalid token supplied

There is no such problem using curl and the same token, e.g.

% curl --silent --request POST --url "https://gitlab.com/api/v4/user/runners" \
  --data "runner_type=group_type" \
  --data "group_id=123456" \
  --data "description=sample group runner" \
  --data "tag_list=tag1,tag2,tag3" \
  --header "PRIVATE-TOKEN: glpat-bcK_xxxxxxxxxxxxxxxx"
{"id":22222222,"token":"glrt-yyyyyyyyyyyyyyyyyyyy","token_expires_at":null}

Specifications

  • python-gitlab version: v3.12.0
  • API version you are using (v3/v4): v4
  • Gitlab server version (or gitlab.com): gitlab.com
  • Debian 12

@harridu your curl example uses the new user runner registration endpoint, but you python code is using the old instance level endpoint. The python-gitlab equivalent to your curl example is documented in https://python-gitlab.readthedocs.io/en/stable/gl_objects/users.html#create-new-runner. I'll close this but if you have any more questions feel free to ask here!