Repository navigation
Closed
Description
Description of the problem, including code/CLI snippet
In project-status.py ...
for this_project in options.project:
this_project = my_gitlab.projects.get(this_project)
print("Adding project:", this_project.path_with_namespace)
projects = projects + [this_project]- when this_project provided in "namespace/project_name" format, projects.get() fails with 404 error.
- when this_project specified in project_id format, projects.get() succeeds.
- same API access token for both forms of request.
- access token is a project level token with full rights.
Expected Behavior
this_project = my_gitlab.projects.get("namespace/project_name") succeeds
Actual Behavior
this_project = my_gitlab.projects.get("namespace/project_name") fails with 404 error
% ./project-status.py --config ~/.python-gitlab.cfg --section gitlab-https --project https-phase2/ha-proxy-migration
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/gitlab/exceptions.py", line 330, in wrapped_f
return f(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/gitlab/mixins.py", line 139, in get
server_data = self.gitlab.http_get(path, **kwargs)
File "/usr/local/lib/python3.10/site-packages/gitlab/client.py", line 790, in http_get
result = self.http_request(
File "/usr/local/lib/python3.10/site-packages/gitlab/client.py", line 756, in http_request
raise gitlab.exceptions.GitlabHttpError(
gitlab.exceptions.GitlabHttpError: 404: 404 Not Found
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/wrowe/git-repos/python-gitlab/./project-status.py", line 139, in <module>
this_project = my_gitlab.projects.get(this_project)
File "/usr/local/lib/python3.10/site-packages/gitlab/v4/objects/projects.py", line 775, in get
return cast(Project, super().get(id=id, lazy=lazy, **kwargs))
File "/usr/local/lib/python3.10/site-packages/gitlab/exceptions.py", line 332, in wrapped_f
raise error(e.error_message, e.response_code, e.response_body) from e
gitlab.exceptions.GitlabGetError: 404: 404 Not Found% ./project-status.py --config ~/.python-gitlab.cfg --section gitlab-https --project 3894
Adding project: https-phase2/ha-proxy-migration
Scanning issues for ha-proxy-migration ...
Building report for ha-proxy-migration ...
Writing report file ...Specifications
- python-gitlab version: 3.6.0
- API version you are using (v3/v4): v4
- Gitlab server version (or gitlab.com): 14.0.12 Community Edition
Metadata
Metadata
Assignees
Labels
No labels
Activity
[-]Can't gl.projects.get with project_with_namespace[/-][+]Can't gl.projects.get with namespace/project_name[/+][-]Can't gl.projects.get with namespace/project_name[/-][+]gl.projects.get() fails when provided "namespace/project_name"[/+]walterrowe commentedon Jul 6, 2022
Don't know if this is also helpful.
JohnVillalovos commentedon Jul 6, 2022
Hi @walterrowe
I know that it does work to get by the path as I use that often. So this is odd.
Can you add a print statement so we see the name of the project?
walterrowe commentedon Jul 6, 2022
See the first line of output for the failure. The last command line arg is the project with name space.
JohnVillalovos commentedon Jul 6, 2022
But can you print the value that you are sending to the
get()method please. I would like to see. One thought I had is that could possibly be iterating over the string and thus the project trying to be retrieved could be the letterh. Printing the value will help figure that out.walterrowe commentedon Jul 6, 2022
Output showing value and type ...
argparser code that processes the command line option for project.
walterrowe commentedon Jul 6, 2022
Looking in mixins.py I see that GetMixin calls utils.EncodedID.
python-gitlab/gitlab/mixins.py
Lines 130 to 131 in d5de4b1
utils.py EncodedID() has these lines:
python-gitlab/gitlab/utils.py
Lines 127 to 128 in d5de4b1
in a terminal window I can type this and it works.
JohnVillalovos commentedon Jul 6, 2022
Very odd 😕
You can add this to your program after getting the
gl=gitlab.Gitlab()value.This will output the data that is being sent to the server.
JohnVillalovos commentedon Jul 6, 2022
The quoting is working as I expected:
walterrowe commentedon Jul 6, 2022
with debug enabled ...
JohnVillalovos commentedon Jul 6, 2022
Also if you want to hop on the Gitter channel I could try to help in a more interactive way. https://gitter.im/python-gitlab/Lobby
walterrowe commentedon Jul 6, 2022
Would love the interactive help but I can't connect to the gitter.im channel from this restricted network.
JohnVillalovos commentedon Jul 6, 2022
One thing I was reading was this:
https://docs.gitlab.com/ee/api/#namespaced-path-encoding
A project’s path isn’t necessarily the same as its name. A project’s path is found in the project’s URL or in the project’s settings, under General > Advanced > Change path.
But it looks like it is correct 😕
Can you try this?
Want to make sure there isn't some extra unseen characters in the path.
Another possibility is that Gitlab 14.0 has a bug, but I wouldn't think so.
JohnVillalovos commentedon Jul 6, 2022
The path being sent to Gitlab looks correct to me.
send: b'GET /api/v4/projects/https-phase2%2Fha-proxy-migrationwalterrowe commentedon Jul 6, 2022
The program does that.
JohnVillalovos commentedon Jul 6, 2022
I don't see quotes around the project name in "Adding project" can you do it with
walterrowe commentedon Jul 6, 2022
Yes.
the python script snippet:
is it possible this is a bug in the 14.0.12 CE API? we are upgrading to 15.x over time. gitlab upgrades require iterating over each version unfortunately.
JohnVillalovos commentedon Jul 6, 2022
Sadly I don't know. It seems like python-gitlab is sending the correct path to the Gitlab server based on the debug output.
The only other shot in the dark I have is to also print the url-encoded ID form.
And compare to what trying to send.
JohnVillalovos commentedon Jul 6, 2022
Possible yes. I don't know though. I would think it isn't as it seems like a big bug. But not sure.
JohnVillalovos commentedon Jul 6, 2022
Also. Is this failing for all/other projects when doing a get using a path?
walterrowe commentedon Jul 6, 2022
RESOLVED:
On this specific gitlab instance, I had to use
https://my.gitlab.server/toplevel_entrypathfor url in ~/.python-gitlab.cfgThis fails:
This works:
We don't have this "toplevel_entrypath" layer in our paths on our other gitlab instances. I need to talk to her gitlab admin about that.
JohnVillalovos commentedon Jul 6, 2022
Woo hoo!! Glad you figured it out. I was perplexed for sure.
JohnVillalovos commentedon Jul 6, 2022
Just curious. Does the
web_urlattribute show the correct path? Maybe next time I will ask to see that value too 🤓Also confusing to me why the integer ID worked. Weird.
walterrowe commentedon Jul 6, 2022
The integer ID probably worked because gitlab searches a different field in the database for an ID versus for a namespace/project_name.
and since you asked ...
definitely worth also asking for the web_url in the future.
JohnVillalovos commentedon Jul 6, 2022
Thanks. I'll try to remember that!