I tried to create Github repository through entering the following command in the R console:
devtools::use_github("https://github.com/SimonFans/RP")
But it gives such kind of error:
Error in gh::gh("POST /user/repos", name = pkg$Package, description = gsub("\n", :
GitHub API error (401): 401 Unauthorized
Bad credentials
Does anyone knows how to solve that?
If you execute this command, a new GitHub repo will be created via the GitHub API, therefore you must provide a GitHub
personal access token (PAT) via the argument auth_token, which defaults to the value of the
GITHUB_PAT environment variable. Obtain a PAT from https://github.com/settings/tokens.
The "repo" scope is required which is one of the default scopes for a new PAT.
You don't have this variable set therefore you need to specify it explicitly in your call to function use_github.
Related
I'm using the gmailr package for sending emails from a r script.
Locally it's all working fine, but when I try to run this during a docker build step in google cloud I'm getting an error.
I implemented it in the following way described here.
So basically, locally the part of my code for sending emails looks like this:
gm_auth_configure(path = "credentials.json")
gm_auth(email = TRUE, cache = "secret")
gm_send_message(buy_email)
Please note, that I renamed the .secret folder to secret, because I want to deploy my script with docker in gcloud and didn't want to get any unexpected errors due to the dot in the folder name.
This is the code, which I'm now trying to run in the cloud:
setwd("/home/rstudio/")
gm_auth_configure(path = "credentials.json")
options(
gargle_oauth_cache = "secret",
gargle_oauth_email = "email.which.was.used.to.get.secret#gmail.com"
)
gm_auth(email = "email.which.was.used.to.get.secret#gmail.com")
When running this code in a docker build process, I'm receiving the following error:
Error in gmailr_POST(c("messages", "send"), user_id, class = "gmail_message", :
Gmail API error: 403
Request had insufficient authentication scopes.
Calls: gm_send_message -> gmailr_POST -> gmailr_query
I can reproduce the error locally, when I do not check the
following box.
Therefore my first assumption is, that the secret folder is not beeing pushed correctly in the docker build process and that the authentication tries to authenticate again, but in a non interactive-session the box can't be checked and the error is thrown.
This is the part of the Dockerfile.txt, where I'm pushing the files and running the script:
#2 ADD FILES TO LOCAL
COPY . /home/rstudio/
WORKDIR /home/rstudio
#3 RUN R SCRIPT
CMD Rscript /home/rstudio/run_script.R
and this is the folder, which contains all files / folders beeing pushed to the cloud.
My second assumption is, that I have to somehow specify the scope to use google platform for my docker image, but unfortunately I'm no sure where to do that.
I'd really appreciate any help! Thanks in advance!
For anyone experiencing the same problem, I was finally able to find a solution.
The problem is that GCE auth is set by the "gargle" package, instead of using the "normal user OAuth flow".
To temporarily disable GCE auth, I'm using the following piece of code now:
library(gargle)
cred_funs_clear()
cred_funs_add(credentials_user_oauth2 = credentials_user_oauth2)
gm_auth_configure(path = "credentials.json")
options(
gargle_oauth_cache = "secret",
gargle_oauth_email = "sp500tr.cloud#gmail.com"
)
gm_auth(email = "email.which.was.used.for.credentials.com")
cred_funs_set_default()
For further references see also here.
I'm using RStudio + Github and have been following the instructions here: https://happygitwithr.com/https-pat.html
It works great, except that within a couple of hours the PAT no longer works and I'm prompted to enter a username/password. I go back and generate a new PAT, and repeat. Here's the code I'm using.
> usethis::create_github_token()
• Call `gitcreds::gitcreds_set()` to register this token in the local Git credential store
It is also a great idea to store this token in any password-management software that you use
✔ Opening URL 'https://github.com/settings/tokens/new?scopes=repo,user,gist,workflow&description=DESCRIBE THE TOKEN\'S USE CASE'
> usethis::create_github_token()
• Call `gitcreds::gitcreds_set()` to register this token in the local Git credential store
It is also a great idea to store this token in any password-management software that you use
✔ Opening URL 'https://github.com/settings/tokens/new?scopes=repo,user,gist,workflow&description=DESCRIBE THE TOKEN\'S USE CASE'
> gitcreds::gitcreds_set()
? Enter password or token: <token>
-> Adding new credentials...
-> Removing credetials from cache...
-> Done.
I have also set the following:
git config --global credential.helper 'cache --timeout=10000000'
The PAT can be stored as environment variable so a key=value assignment in the ~/.Renviron file is a very possible solution.
Another is to explicitly inject it from ~/.Rprofile via Sys.setenv(key="value").
You can test either in any R session via
> v <- Sys.getenv()
> "GITHUB_PAT" %in% names(v)
[1] TRUE
>
When you create a PAT (in the GitHub UI) you can give it explicit lifetimes. I happily re-used on this week which I created a year ago for a particular scripting need.
Probably a usage or settings issue:
I'm trying to use R's googleCloudStorageR package to upload files to my google storage bucket.
Running:
googleCloudStorageR::gcs_upload("test/my_test.csv")
prints these messages:
2020-05-11 18:57:19 -- File size detected as 368 bytes
2020-05-11 18:57:20> Request Status Code: 400
And then this error:
Error: API returned: Cannot insert legacy ACL for an object when uniform bucket-level access is enabled. Read more at https://cloud.google.com/storage/docs/uniform-bucket-level-access.
Is there a different usage to googleCloudStorageR::gcs_upload that will succeed? (not clear from its documentation
If I set predefinedAcl to "default" I get a JSON related error:
Error : lexical error: invalid char in json text
This error message is followed by some html code and following that this message:
> xdg-open: unexpected argument 'minimum-scale=1,'
Try 'xdg-open --help' for more information.`.
I'm not sure what JSON it's referring to but if it's the JSON I set googleCloudStorageR to authenticate access to my bucket than I'm surprised it's complaining at this stage
It looks like in https://github.com/cloudyr/googleCloudStorageR/pull/84 it got support to inherit the bucket level ACL if you set predefinedAcl to default. In your example this would be:
googleCloudStorageR::gcs_upload("test/my_test.csv", predefinedAcl = "default")
The issue has been resolved by the googleCloudStorageR developers. It is not yet on the CRAN distribution but it installing it from github (devtools::install_github("cloudyr/googleCloudStorageR")) should do.
And the usage is:
googleCloudStorageR::gcs_upload("test/my_test.csv", predefinedAcl = "bucketLevel")
I am trying to install a sample package from my github repo:
https://github.com/jpmarindiaz/samplepkg
I can install it when the repo is public using any of the following commands through the R interpreter:
install_github("jpmarindiaz/rdali")
install_github("rdali",user="jpmarindiaz")
install_github("jpmarindiaz/rdali",auth_user="jpmarindiaz")
But when the git repository is private I get an Error:
Installing github repo samplepkg/master from jpmarindiaz
Downloading samplepkg.zip from
https://github.com/jpmarindiaz/samplepkg/archive/master.zip
Error: client error: (406) Not Acceptable
I haven't figured out how the authentication works when the repo is private, any hints?
Have you tried setting a personal access token (PAT) and passing it along as the value of the auth_token argument of install_github()?
See ?install_github way down at the bottom (Package devtools version 1.5.0.99).
Create an access token in:
https://github.com/settings/tokens
Check the branch name and pass it to ref
devtools::install_github("user/repo"
,ref="main"
,auth_token = "tokenstring"
)
A more modern solution to this problem is to set your credentials in R using the usethis and credentials packages.
#set config
usethis::use_git_config(user.name = "YourName", user.email = "your#mail.com")
#Go to github page to generate token
usethis::create_github_token()
#paste your PAT into pop-up that follows...
credentials::set_github_pat()
#now remotes::install_github() will work
remotes::install_github("username/privaterepo")
More help at https://happygitwithr.com/common-remote-setups.html#common-remote-setups
I'm creating a very simple sqldf app where I want to query postgresql database and return results. Here is my R code:
getproperties <- function(name="") {
options(sqldf.RPostgreSQL.user ="user",
sqldf.RPostgreSQL.password ="password",
sqldf.RPostgreSQL.dbname ="db",
sqldf.RPostgreSQL.host ="server",
sqldf.RPostgreSQL.port =5432,
sqldf.driver = "PostgreSQL")
property <- sqldf("select name, url from aston_hotels.property")
return(property)
}
When I call this using OpenCpu
curl http://localhost/ocpu/user/kesav/library/mylib/getproperties/json --data name=kk
I get the following error
R call failed: process died.
Don't know what's I'm doing wrong. Can anyone point me to an example on how to use DBI from OpenCpu?
Thanks in advance
If the function works when running it on the same machine the terminal but not within OpenCPU, it is likely a security problem. Please check in /var/log/kern.log if there are any lines printed containing DENIED when using the application.
If this is the case, you can add the appropriate privileges the the security profile by editing
/etc/apparmor.d/opencpu.d/custom
Also see the server manual section titled Customizing the security profile on this topic.