gitlabr icon indicating copy to clipboard operation
gitlabr copied to clipboard

how to debug `Not Found (HTTP 404)` issue from `gl_list_projects()`

Open markrobinsonuzh opened this issue 2 years ago • 4 comments

I'm not sure if this is the best place to get help with this, but I'll try anyway ..

So, I get an error like this:

> library(gitlabr)
> set_gitlab_connection(
+   gitlab_url = "https://renkulab.io/gitlab",
+   private_token = Sys.getenv("GITLAB_COM_TOKEN")
+ )
> gl_list_projects(max_page = 2, owned = FALSE) 
Error in http_error_or_content(.) : Not Found (HTTP 404).

And yes, Sys.getenv("GITLAB_COM_TOKEN") is defined and is correct, because I can use the same token in something like this:

> system('curl https://renkulab.io/gitlab/api/v4/user -H "private-token: [snip]"')
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1024  100  1024    0     0   3778      0 --:--:-- --:--:-- --:--:--  3764
{"id":478,"username":"mark.robinson","name":"Mark Robinson","state":"active"[snip]

..

> system('curl https://renkulab.io/gitlab/api/v4/projects -H "private-token: [snip]"')
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 98876    0 98876    0     0  97800      0 --:--:--  0:00:01 --:--:-- 97800
[{"id":22179,"description":null,"name":"eng209-2022-partie1","name_with_namespace":[snip]

I've tried a few other controls:

  • accessing my account on gitlab.com, all these commands work
  • using the python gitlab module, all the corresponding commands work
  • I've done this on 2 Mac computers

I'd really like to use the R package though .. any ideas how to debug / workarounds?

Thanks in advance, Mark

markrobinsonuzh avatar Oct 13 '22 19:10 markrobinsonuzh

Hi @markrobinsonuzh , I do not see any other problem than the token.
Sometimes, I think I used the correct token, but I use the one of another GitLab instance... Can you write the token directly in the set_gitlab_connection() ?
When you created the token on your renkulab gitlab, did you check the "api" ?

statnmap avatar Oct 16 '22 09:10 statnmap

Dear @markrobinsonuzh , Did you try my propositions ? Is your problem still present ? If not, can you tell how you debugged it to help other users who may face this ? And then, close the issue. Thank you for your feedback.

statnmap avatar Nov 08 '22 22:11 statnmap

I'm having a similar issue, but I've found some workarounds that indicate there is definitely an issue with how the gitlab() function works in conjunction with connections created via set_gitlab_connection().

If I run:

library(gitlabr)
set_gitlab_connect(gitlab_url = "https://my.gitlab.url",private_token = Sys.getenv("GITLAB_PAT"))
gl_list_projects(max_page = 1,owned = TRUE)

I get a correct list of my projects with their IDs. However, if I then try:

gl_list_files(project = XXXX)

using one of the project ID numbers returned by gl_list_projects() I get an HTTP 404 error:

Error in http_error_or_content(.) : Not Found (HTTP 404)

However, I can successfully run the list files API request if I load gitlabr, do NOT create a connection via set_gitlab_connection() but instead run this directly:

gitlab(c("projects",XXXX,"repository","tree"),
  api_root = "https://my.gitlab.url/api/v4",
  private_token = Sys.getenv("GITLAB_PAT"),
  verb = httr::GET)

Then I get a list of files in the selected project.

joranE avatar Jun 01 '23 15:06 joranE

Aha! My problem appears to be with an (apparently undocumented) default value for the argument ref which is fetched from the option gitlabr.main. It defaults to "main" but if your default primary branch name happens to be something else (like the very common "master") it will return a 404 error, not being able to find a branch called "main". This behavior should probably be much more prominent in the documentation.

joranE avatar Jun 01 '23 16:06 joranE

  • gitlabr is now more verbose when projects are specified by their name, so that you can know if the id was detected
  • Documentation for ref now specifies that the default is 'main'

statnmap avatar May 15 '24 10:05 statnmap