Skip to content
  • Jack Griffith @JackGriffith ·

    Trying to run this I'm getting the following error. I just installed the python-gitlab library so I expect it is the current one. Any suggestions?

    Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/gitlab/base.py", line 85, in getattr return self.dict["_updated_attrs"][name] KeyError: 'access_tokens'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/gitlab/base.py", line 88, in getattr value = self.dict["_attrs"][name] KeyError: 'access_tokens'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/gitlab/base.py", line 108, in getattr return self.dict["_parent_attrs"][name] KeyError: 'access_tokens'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last): File "expired_tokens2.py", line 45, in print_expired_tokens(group_id, "2024-05-14") File "expired_tokens2.py", line 12, in print_expired_tokens group_tokens = group.access_tokens.list(get_all=True) File "/usr/local/lib/python3.6/site-packages/gitlab/base.py", line 110, in getattr raise AttributeError(name) AttributeError: access_tokens

  • Manuel Grabowski @manuelgrabowski ·

    Hm, that's odd. I'm on Python 3.12, but I don't think that should make a difference. Can you check via pip show python-gitlab what library version it has installed?

  • Trying to run this script I'm getting the following error:

    Could not get group information, likely auth error: 404

    Any insights on what the auth error might be since its a 404 response and not like a 401 or 403, etc?

  • Manuel Grabowski @manuelgrabowski ·

    404 could still indiciate that the token you're using doesn't have enough permissions to see that project – some endpoints return a 404 in these cases to avoid information leakage. Does the token you're using have enough permission to query the group you're trying to analyze?

    (A simple test would be running this and checking if that returns an error or good data: curl --header "PRIVATE-TOKEN: <YOUR_TOKEN>" "https://gitlab.com/api/v4/groups/<GROUP_ID>")

  • Jack Griffith @JackGriffith ·

    @manuelgrabowski Well, it's odd because it is showing an old version, but I just installed it yesterday. I guess I need to see why I didn't get the current one. Thanks!

    [dt10292@da3t-gen-ans-cis002 scripts]$ pip show python-gitlab Name: python-gitlab Version: 2.10.1 Summary: Interact with GitLab API Home-page: https://github.com/python-gitlab/python-gitlab Author: Gauvain Pocentek Author-email: gauvain@pocentek.net License: LGPLv3 Location: /usr/local/lib/python3.6/site-packages Requires: requests-toolbelt, requests Required-by:

  • Manuel Grabowski @manuelgrabowski ·

    @PhillS23 You can run it like this: GITLAB_TOKEN=<YOUR_TOKEN> python3 expired_tokens.py 12345, or do an export GITLAB_TOKEN=<YOUR_TOKEN> first and then run python3 expired_tokens.py 12345. Alternatively just replace os.environ.get("GITLAB_TOKEN") in the script with "<YOUR_TOKEN>" to hardcode it there, then running python3 expired_tokens.py 12345 without any extra steps should also work.


    @JackGriffith It might be due to Python 3.6 after all, looking at the Changelog they do seem to have dropped support for that version a while back: https://python-gitlab.readthedocs.io/en/stable/changelog.html#v3-0-0-2022-01-05 – so you're likely getting the last compatible version.

  • I seem to be getting 401 errors even though the test works EDIT - RESOLVED, see below

    export GITLAB_TOKEN=<READ_API_TOKEN>
    export GROUP_ID=<GROUP_ID>
    
    # Works
    curl -I --header "PRIVATE-TOKEN: $GITLAB_TOKEN" "https://gitlab.com/api/v4/groups/$GROUP_ID"
    
    HTTP/2 200 
    date: Thu, 16 May 2024 16:47:20 GMT
    ...
    
    # Fails
    python3 expired_tokens.py $GROUP_ID
    
    File "/home/cvandesande/playground/lib/python3.11/site-packages/gitlab/client.py", line 787, in http_request
        raise gitlab.exceptions.GitlabAuthenticationError(
    gitlab.exceptions.GitlabAuthenticationError: 401: 401 Unauthorized
    

    Fix: I created a new token from an account with owner level permissions and then it worked.

    Edited by Christopher van de Sande
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment