Title: Redirects with dot in project name do not resolve correctly and raise 404 error instead · Issue #3299 · python-gitlab/python-gitlab · GitHub
Open Graph Title: Redirects with dot in project name do not resolve correctly and raise 404 error instead · Issue #3299 · python-gitlab/python-gitlab
X Title: Redirects with dot in project name do not resolve correctly and raise 404 error instead · Issue #3299 · python-gitlab/python-gitlab
Description: Redirects for projects with dot in name do not resolve correctly When a request is made to GitLab for a project that will be redirected to a new path (HTTP 302 response), a quirk with GitLab's API is that the path_with_namespace passed t...
Open Graph Description: Redirects for projects with dot in name do not resolve correctly When a request is made to GitLab for a project that will be redirected to a new path (HTTP 302 response), a quirk with GitLab's API ...
X Description: Redirects for projects with dot in name do not resolve correctly When a request is made to GitLab for a project that will be redirected to a new path (HTTP 302 response), a quirk with GitLab's ...
Opengraph URL: https://github.com/python-gitlab/python-gitlab/issues/3299
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Redirects with dot in project name do not resolve correctly and raise 404 error instead","articleBody":"## Redirects for projects with dot in name do not resolve correctly\n\nWhen a request is made to GitLab for a project that will be redirected to a new path (HTTP 302 response), a quirk with GitLab's API is that the `path_with_namespace` passed to `https://gitlab.com/api/vi/projects/{encoded_path_with_namespace}` needs to have any dots encoded to `%2E` in order for the `Location` in the response header to be correct. Although this seems to be a \"bug\" with GitLab itself, this package could easily work around it by replacing dots with `%2E` which then makes everything work fine.\n\nWe can demonstrate this pretty simply with the following code, using a project I created and then renamed to demonstrate this behaviour:\n\n```\nimport gitlab\ngl = gitlab.Gitlab(\"https://gitlab.com\")\ngl.projects.get(\"simon.burton1/redirect.test\")\n```\n\nWhich causes:\n\n```\ngitlab.exceptions.GitlabGetError: 404: 404 Project Not Found\n```\n\nWe can see *why* this is happening by repeating the same with curl. First by doing exactly what python-gitlab is doing in `EncodedId` doing by using the url encoded fragment, as `urllib.parse.quote` would return with `safe=\"\"`:\n\n```\ncurl --request GET --url \"https://gitlab.com/api/v4/projects/simon.burton1%2Fredirect.test\"\nThis resource has been moved permanently to https://gitlab.com/api/v4/projects/76187413.test\n```\n\nNote the erroneous `.test` that is added to the redirect message by GitLab. And checking the response headers, we can see that the `Location` does indeed get this erroneous url, which will cause any redirect to ultimately 404, as that path obviously does not exist:\n\n```\n\u003c location: https://gitlab.com/api/v4/projects/76187413.test\n```\n\nHowever, if we encode the dots in the project path, as well as the slashes:\n\n```\ncurl --request GET --url \"https://gitlab.com/api/v4/projects/simon%2Eburton1%2Fredirect%2Etest\"\nThis resource has been moved permanently to https://gitlab.com/api/v4/projects/76187413\n```\n\nAnd we can see that the redirect location header is indeed correct:\n\n```\n\u003c location: https://gitlab.com/api/v4/projects/76187413\n```\n\nWe can validate that this is not a more general issue with API redirects and is limited to this behaviour with dots, by requesting another redirected project that *doesn't* have dots in the `path_with_namespace`, thus:\n\n```\ngl.projects.get(\"gitlab-org/gitlab-ce\")\n\u003cProject id:13083 path_with_namespace:gitlab-org/gitlab-foss\u003e\n```\n\n## Expected Behaviour\n\n`python-gitlab` should encode any dots in `Gitlab.projects.get` as `%2E` to work around the probable bug in GitLab's own API, so that `projects.get(\"redirected.project\")` will return the new project.\n\nAlthough one could argue that this is a bug in GitLab, which may or may not be the case, it's not actually documented about *how* these paths should be encoded, just that they should be \"url encoded\" (https://docs.gitlab.com/api/rest/#namespaced-paths), and encoding dots is not \"wrong\", per se. Just usually unnecessary. \n\nSecondly, we know that even if it were a bug in GitLab's API, they won't fix it for 7 years, and the workaround in `python-gitlab` would be both a valid url encoding anyway, and would enable users of this package to be redirected correctly when requesting moved projects with dots in their namespaced paths.\n\n## Actual Behaviour\n\nA 404 error is returned for an otherwise resolvable redirect when `projects.get(\"redirected.project\")` is called with a dot in the project path, as per this example.\n\n## Suggested Fix\n\nIn `gitlab.utils.EncodedId.__new__()`, updating this line works in this case, but I haven't tested whether this has any knock-on effect for anything else that calls this encoder, so I haven't raised a PR as I cannot prove that there are not regressions without more time to test. Happy to raise a PR though, if you would prefer that:\n\n```\n248 if isinstance(value, str):\n249 value = urllib.parse.quote(value, safe=\"\").replace(\".\", \"%2E\")\n\n```\n\n## Specifications\n\n - python-gitlab version: 7.0.0\n - Gitlab server version (or gitlab.com): gitlab.com\n","author":{"url":"https://github.com/uglybug","@type":"Person","name":"uglybug"},"datePublished":"2025-11-18T23:08:52.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/3299/python-gitlab/issues/3299"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a7141df3-41ab-c833-15d2-3a8f2f322ea1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AD76:242157:9172754:BCC046A:697607FE |
| html-safe-nonce | ba29ec015152473dd3b5f50bfdd1643355135912cae2b3754a8044c2dab8fc7f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRDc2OjI0MjE1Nzo5MTcyNzU0OkJDQzA0NkE6Njk3NjA3RkUiLCJ2aXNpdG9yX2lkIjoiODE5NTYyNzkyNzA4OTg0MjE3NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 5a36b6f657a9e7640417df3ea97074baab4b1c7bce0477c02c74c6afc5067939 |
| hovercard-subject-tag | issue:3640336047 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python-gitlab/python-gitlab/3299/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4ec24a84e98166bf9ef989880ccd727f1d66c80ea330d330d25ebc8932f9a824/python-gitlab/python-gitlab/issues/3299 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4ec24a84e98166bf9ef989880ccd727f1d66c80ea330d330d25ebc8932f9a824/python-gitlab/python-gitlab/issues/3299 |
| og:image:alt | Redirects for projects with dot in name do not resolve correctly When a request is made to GitLab for a project that will be redirected to a new path (HTTP 302 response), a quirk with GitLab's API ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | uglybug |
| hostname | github.com |
| expected-hostname | github.com |
| None | c6814b4cc7afd45cd6e64525d0cff0e76dd802f315a5b0e55a7abda1d1d070d0 |
| turbo-cache-control | no-preview |
| go-import | github.com/python-gitlab/python-gitlab git https://github.com/python-gitlab/python-gitlab.git |
| octolytics-dimension-user_id | 28886265 |
| octolytics-dimension-user_login | python-gitlab |
| octolytics-dimension-repository_id | 8077625 |
| octolytics-dimension-repository_nwo | python-gitlab/python-gitlab |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 8077625 |
| octolytics-dimension-repository_network_root_nwo | python-gitlab/python-gitlab |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4ea235bfed58ef16c8a5642b3ac64b74f10c9f52 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width