r-lib / remotes

Install R packages from GitHub, GitLab, Bitbucket, git, svn repositories, URLs
https://remotes.r-lib.org/
Other
330 stars 152 forks source link

Can not install package via install_github #727

Closed Dagwbl closed 1 year ago

Dagwbl commented 1 year ago

Here is the Error information

> remotes::install_github('rstudio/blogdown')
Using github PAT from envvar GITHUB_TOKEN
Error: Failed to install 'blogdown' from GitHub:
  Failed to connect to api.github.com port 443: Connection refused

System detail

Other

I can access github normally

Microsoft Windows [Version 10.0.22621.521]
(c) Microsoft Corporation. All rights reserved.

E:\Documents\Rmarkdown\blog>ssh -T git@github.com
Hi Dagwbl! You've successfully authenticated, but GitHub does not provide shell access.
gaborcsardi commented 1 year ago

Does this error persist? If yes, then maybe you have a firewall?

The ssh test is irrelevant, because that does not use the HTTPS. If you want to test w/o remotes, you can do something like this:

download.file("https://api.github.com/repos/rstudio/blogdown", tmp <- tempfile())
jsonlite::readJSON(tmp)
Dagwbl commented 1 year ago

First of all, thank you for your reply. When I type

download.file("https://api.github.com/repos/rstudio/blogdown", tmp <- tempfile()) jsonlite::readJSON(tmp)

I get the traceback,

> download.file("https://api.github.com/repos/rstudio/blogdown", tmp <- tempfile())
trying URL 'https://api.github.com/repos/rstudio/blogdown'
Error in download.file("https://api.github.com/repos/rstudio/blogdown",  : 
  cannot open URL 'https://api.github.com/repos/rstudio/blogdown'
In addition: Warning message:
In download.file("https://api.github.com/repos/rstudio/blogdown",  :
  URL 'https://api.github.com/repos/rstudio/blogdown': status was 'Couldn't connect to server'

I thought about the settings related to the firewall, I modified the host file before, and now I've modified it back. like this

# rstudio
# 140.82.113.4 github.com

Then try again

> download.file("https://api.github.com/repos/rstudio/blogdown", tmp <- tempfile())
trying URL 'https://api.github.com/repos/rstudio/blogdown'
Error in download.file("https://api.github.com/repos/rstudio/blogdown",  : 
  cannot open URL 'https://api.github.com/repos/rstudio/blogdown'
In addition: Warning message:
In download.file("https://api.github.com/repos/rstudio/blogdown",  :
  URL 'https://api.github.com/repos/rstudio/blogdown': status was 'SSL connect error'

I search the error about 'SSL connect error', and I add the proxy setting, like this

> Sys.setenv(https_proxy="http://127.0.0.1:1080")
> download.file("https://api.github.com/repos/rstudio/blogdown", tmp <- tempfile())
trying URL 'https://api.github.com/repos/rstudio/blogdown'
Content type 'application/json; charset=utf-8' length 5930 bytes
downloaded 5930 bytes
> jsonlite::readJSON(tmp)
Error: 'readJSON' is not an exported object from 'namespace:jsonlite'

I thought the problem was solved, but the error is persistent.

> download.file("https://api.github.com/repos/rstudio/blogdown", tmp <- tempfile())
trying URL 'https://api.github.com/repos/rstudio/blogdown'
Content type 'application/json; charset=utf-8' length 5930 bytes
downloaded 5930 bytes

> remotes::install_github('rstudio/blogdown')
Using github PAT from envvar GITHUB_TOKEN
Error: Failed to install 'blogdown' from GitHub:
  Failed to connect to api.github.com port 443: Connection refused
gaborcsardi commented 1 year ago

Because remotes uses the curl package if available. Set standalone mode (see README), or fix your proxy for the curl package (and libcurl) as well.

Dagwbl commented 1 year ago

This standalone mode doesn't seem to work. But the traceback info was updated.

> Sys.setenv(R_REMOTES_STANDALONE="true")
> remotes::install_github('rstudio/blogdown')
Using github PAT from envvar GITHUB_TOKEN
Error: Failed to install 'blogdown' from GitHub:
  cannot open URL 'https://api.github.com/repos/rstudio/blogdown/commits/HEAD'

and I don't know how to fix my proxy for the curl package and libcurl, I will search for it.

gaborcsardi commented 1 year ago

You still need to set the proxy, even if you set standalone mode. Standalone mode makes remotes use download.file(), so if that works then remotes should work as well, unless you are rate limited.

Dagwbl commented 1 year ago

It's really a little weird. Even if I set up both the proxy and the standalone mode

> Sys.setenv(https_proxy="http://127.0.0.1:1080")
> Sys.setenv(R_REMOTES_STANDALONE="true")
> download.file("https://api.github.com/repos/rstudio/blogdown", tmp <- tempfile()) 
trying URL 'https://api.github.com/repos/rstudio/blogdown'
Content type 'application/json; charset=utf-8' length 5930 bytes
downloaded 5930 bytes

> remotes::install_github('rstudio/blogdown')
Using github PAT from envvar GITHUB_TOKEN
Error: Failed to install 'blogdown' from GitHub:
  cannot open URL 'https://api.github.com/repos/rstudio/blogdown/commits/HEAD'
gaborcsardi commented 1 year ago

The second one uses GITHUB_TOKEN, so maybe that is not a proper token, or it is rate limited. Try to unset it.

Dagwbl commented 1 year ago

It works! After I set it up. Thank you for your patience.

gaborcsardi commented 1 year ago

Just a heads up, lot of packages use the curl package, so you'll want to look up how to set the proxy for that, at some point: https://jeroen.cran.dev/curl/articles/windows.html

Dagwbl commented 1 year ago

I will learn about it. Thank you.