FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

projects.get() raises error when project is specified as "userspace/name" rather than ID · Issue #913 · python-gitlab/python-gitlab · GitHub

projects.get() raises error when project is specified as "userspace/name" rather than ID #913

Description

Description of the problem, including code/CLI snippet

Attempt to make a query using the project's path, per the example in the documentation.

gl.projects.get('mygroup/myname')

Expected Behavior

python-gitlab resolves the group and project name, returning a Project object for that project.

Actual Behavior

Exception is raised with the following error:

Error encountered triggering pipeline: 404: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /api/v4/projects/mygroup/myname was not found on this server.</p>
</body></html>

From the URL in the error, it appears that the project is not being resolved at all and that python-gitlab is assuming the value passed in was the project ID.

Specifications

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

Activity

  1. bufferoverflow commented on Oct 17, 2019

    Member

    I'm pretty sure this is a doc bug, https://docs.gitlab.com/ee/api/projects.html#get-single-project does also provide a get project by id endpoint only.

  2. terminalmage commented on Oct 17, 2019

    Author

    Yeah, I had suspected this might be the case, as I am relatively familiar with the API and know you can't get the project by anything but the ID.

    I can work around this by using projects.list(search='myname') and then checking each match to see if the namespace and project name both match. So, at the end of the day it's not a blocker for me.

    If the solution is a doc fix, I can submit a pull request. However, if it is deemed useful to add this functionality, I would need to roll up my sleeves and get more familiar with the codebase.

  3. bufferoverflow commented on Oct 18, 2019

    Member

    Whould be awesome to get a contribution within the docs on this from your side.

  4. terminalmage commented on Oct 18, 2019

    Author

    Cool, just opened #914

  5. inakimalerba commented on Oct 31, 2019

    If you read correctly on the doc link @bufferoverflow provided, it says The ID or URL-encoded path of the project.

    The project's doc was correctly but the feature is not working, and I'm not sure why. It appears to me that it's querying the correct endpoint.

    I'd preffer to reopen this issue rather than opening a new one :)

  6. inakimalerba commented on Oct 31, 2019

  7. inakimalerba commented on Oct 31, 2019

    It happen to work on gitlab.com, but not on the instance I previously shared.

    In [1]: import gitlab
    
    In [2]: gl = gitlab.Gitlab('https://gitlab.com')
    
    In [3]: gl.projects.get('inakimalerba/test-project')
    Out[3]: <Project id:13176136>

    I'm trying to debug the reason behind the failure.

    It's possible that the instance admins might have blocked some kind of requests, but the endpoint works good with any other requests.

    In [5]: import requests
    
    In [6]: session = requests.Session()
      ...: session.headers.update({'User-Agent': 'Mozilla/5.0'})
      ...: 
    
    In [7]: gl = gitlab.Gitlab('https://salsa.debian.org/', session=session)
    
    In [8]: gl.projects.get("salsa-ci-team/pipeline")
    
    [...]
    
    /home/ina/.local/lib/python3.7/site-packages/gitlab/exceptions.py in wrapped_f(*args, **kwargs)
       259                 return f(*args, **kwargs)
       260             except GitlabHttpError as e:
    --> 261                 raise error(e.error_message, e.response_code, e.response_body)
       262 
       263         return wrapped_f
    
    GitlabGetError: 404: 404 Project Not Found
    $ curl https://salsa.debian.org/api/v4/projects/salsa-ci-team%2Fpipeline
    {"id":27916,"description":"♻️ Gitlab CI pipeline definition to build and test Debian projects.","name":"pipeline","name_with_namespace":"Salsa CI Team / pipeline","path":"pipeline","path_with_namespace":"salsa-ci-team/pipeline","created_at":"2018-06-11T16:18:20.834Z","default_branch":"master","tag_list":["autopkgtest","blhc","build","ci","debian","gbp","lintian","package","pipeline","piuparts","reprotest","salsa","test"],"ssh_url_to_repo":"git@salsa.debian.org:salsa-ci-team/pipeline.git","http_url_to_repo":"https://salsa.debian.org/salsa-ci-team/pipeline.git","web_url":"https://salsa.debian.org/salsa-ci-team/pipeline","readme_url":"https://salsa.debian.org/salsa-ci-team/pipeline/blob/master/README.md","avatar_url":null,"star_count":23,"forks_count":32,"last_activity_at":"2019-10-31T19:35:43.180Z","namespace":{"id":3783,"name":"Salsa CI Team","path":"salsa-ci-team","kind":"group","full_path":"salsa-ci-team","parent_id":null,"avatar_url":null,"web_url":"https://salsa.debian.org/groups/salsa-ci-team"}}
  8. nejch commented on Feb 23, 2020

    Member

    Edit: Oops I wrote a lengthy comment but actually it's a simple issue with your trailing slash. I added some debug prints in _build_url() and get this:

    >>> import gitlab
    >>>
    >>> gl = gitlab.Gitlab('https://gitlab.com/')
    >>> gl.projects.get('inakimalerba/test-project')
    Constructed URL:
    https://gitlab.com//api/v4/projects/inakimalerba%2Ftest-project
    <Project id:13176136>
    >>>
    >>> gl = gitlab.Gitlab('https://salsa.debian.org/')
    >>> gl.projects.get("salsa-ci-team/pipeline")
    Constructed URL:
    https://salsa.debian.org//api/v4/projects/salsa-ci-team%2Fpipeline
    Traceback (most recent call last):
    

    So the proxy on gitlab.com handles the double slash but not Apache on salsa.debian.org. For now, removing the trailing slash will work, and for python-gitlab just stripping the trailing slash for the gitlab URL would probably be enough :)

  9. inakimalerba commented on Feb 27, 2020

    Thanks @nejch , sorry for the dumb mistake.

    Does it make sense to revert #914? (which was the real reason behind my comment here).

  10. locked as resolved and limited conversation to collaborators on Nov 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL