drive_auth()函数在提交密码时未创建gargle-oauth令牌。

huangapple go评论115阅读模式
英文:

drive_auth() function not creating gargle-oauth token on password submission

问题

R v3.6.2

RStudio Desktop v1.2.5033

R包 'googledrive' v1.0.0

我编写了一个R脚本,用于上传CSV文件到Google Sheets帐户。为了避免自动化这个过程,我使用了drive_auth()函数来刷新OAuth令牌。代码如下:

drive_auth(
 email = "email@gmail.com",
 path = NULL,
 scopes = "https://www.googleapis.com/auth/drive",
 cache = gargle::gargle_oauth_cache(),
 use_oob = gargle::gargle_oob_default(),
 token = NULL
)

drive_upload(file, overwrite=TRUE, type="spreadsheet")

在Mac和Windows操作系统的计算机上,这会打开一个默认的浏览器,要求输入登录详细信息。当正确输入这些信息后,脚本现在具有上传/编辑文件的权限,googledrive函数随后可以正常工作。它在文件路径中创建了一个授权令牌:

Home/Users/.R/garle/gargle-oauth

然而,在尝试在新的笔记本电脑上进行此操作(该笔记本电脑将用作服务器)时,我遇到了以下错误消息:

错误:无法获取Google凭据。
您是否在非交互式会话中运行googlesheets?考虑:
* 使用'sheets_deauth()'来防止获取凭据的尝试。
* 直接使用所有必要的具体信息调用'sheets_auth()'。

检查gargle-oauth文件夹后,它没有像在输入Google登录详细信息后自动创建OAuth令牌那样创建OAuth令牌。

我在另一台Windows计算机上删除OAuth令牌后重新运行程序,它正常工作,重新从头创建了令牌。我无法确定为什么在这种情况下没有创建该令牌的原因。

英文:

R v3.6.2

RStudio Desktop v1.2.5033

R package 'googledrive' v1.0.0

I have written an R script that uploads csv files to a googlesheets account. In order to avoid having to automate this, I have used the drive_auth() function to refresh the OAuth token. Code is simply:

drive_auth(
 email = "email@gmail.com",
 path = NULL,
 scopes = "https://www.googleapis.com/auth/drive",
 cache = gargle::gargle_oauth_cache(),
 use_oob = gargle::gargle_oob_default(),
 token = NULL
)

drive_upload(file, overwrite=TRUE, type="spreadsheet")

On both a mac and a Windows OS machine, this then opens a default browser that asks for login details. When these are correctly entered, the script now has permissions to upload / edit files and googledrive functions subsequently work. It creates an authority token in the file path:

Home/Users/.R/garle/gargle-oauth

However, when attempting to do this on a new laptop that will be used as a server, I am met with the following error messages:

Error: can't get Google credentials.
Are you running googlesheets in a non-interactive session? Consider:
* sheets_deauth() to prevent the attempt to get credentials.
* call 'sheets_auth()' directly with all necessary specifics.

On inspection of the gargle-oauth folder, it has not created an OAuth token, as it did automatically with other machines on the entering of google login details.

I re-ran the programme on the other windows machine after deleting the OAuth token and it worked fine, creating the token again from scratch. I cannot pinpoint the reason why this token is not being created in this instance.

答案1

得分: 1

我已解决此问题,我将发布一个答案,以防有人遇到类似的问题并在Google搜索时找到此帖子。

当初始化与googledrive的连接时,该软件包使用默认端口1410。无法与Google建立连接,因为一个僵尸进程正在使用此端口。

要终止此进程,请以管理员身份打开Windows命令提示符(或Mac上的命令行)并输入以下netstat命令:

C:\Users>netstat -ano|findstr "PID :1410"

这将(如果在此端口上有任何运行的东西)返回:

Proto Local Address Foreign Address State PID
TCP 0.0.0.0:1410.0.0.0:0 LISTENING 18264

右下角的数字是进程PID,将其输入以下命令以终止该进程:

taskkill /pid 18264 /f

当运行任何R googledrive函数时,现在应该能够授权您的代码与您的Google帐户进行交互,并创建OAuth令牌,以免再次执行此操作。

英文:

I've since solved this and I'm going to post an answer in case anyone is in a similar problem and comes across this post during a google search.

When initialising a connection with googledrive, the package uses the default port of 1410. It was unable to establish a connection with google because a zombie process was using this port.

To kill this process, open up the windows command prompt (or command line on a mac) as admin and enter the netstat command:

C:\Users>netstat -ano|findstr "PID :1410"

This will (if anything is running on this port) return:

Proto Local Address Foreign Address State PID
TCP 0.0.0.0:1410.0.0.0:0 LISTENING 18264

That number at the bottom right is the process PID, enter that into the following command to kill the process:

taskkill /pid 18264 /f

When running any R googledrive functions, you should now be able to authorise your code to interact with your google account and it will create an OAuth token to save you having to go through this again.

答案2

得分: 1

我确认这个问题也在Ubuntu上困扰了我。我通过查找并杀死端口1410上的进程来解决了这个问题(该进程也在40167端口上监听):

me@me:/internal$ netstat -tulpn
(无法识别所有进程,非所有者进程信息不会显示,您需要以root身份查看全部信息。)
活动的互联网连接(仅服务器)
Proto Recv-Q Send-Q 本地地址              外部地址             状态       
PID/程序名称
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:3000            0.0.0.0:*               LISTEN      894/node
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:1410          0.0.0.0:*               LISTEN      21011/R
tcp        0      0 127.0.0.1:40197         0.0.0.0:*               LISTEN      21011/R
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      -
tcp6       0      0 :::22                   :::*                    LISTEN      -
tcp6       0      0 :::25                   :::*                    LISTEN      -
tcp6       0      0 :::443                  :::*                    LISTEN      -
tcp6       0      0 :::1917                 :::*                    LISTEN      1277/node /home/ult
tcp6       0      0 :::3838                 :::*                    LISTEN      -
tcp6       0      0 ::1:6379                :::*                    LISTEN      -
tcp6       0      0 :::80                   :::*                    LISTEN      -
udp        0      0 127.0.0.53:53           0.0.0.0:*                           -

me@me:/internal$ kill -HUP 21011
英文:

I confirm that this problem also got me on Ubuntu. I resolved it by finding and killing the process on port 1410 (which was also listening on 40167):

me@me:/internal$ netstat -tulpn
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       
PID/Program name
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:3000            0.0.0.0:*               LISTEN      894/node
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:1410          0.0.0.0:*               LISTEN      21011/R
tcp        0      0 127.0.0.1:40197         0.0.0.0:*               LISTEN      21011/R
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      -
tcp6       0      0 :::22                   :::*                    LISTEN      -
tcp6       0      0 :::25                   :::*                    LISTEN      -
tcp6       0      0 :::443                  :::*                    LISTEN      -
tcp6       0      0 :::1917                 :::*                    LISTEN      1277/node /home/ult
tcp6       0      0 :::3838                 :::*                    LISTEN      -
tcp6       0      0 ::1:6379                :::*                    LISTEN      -
tcp6       0      0 :::80                   :::*                    LISTEN      -
udp        0      0 127.0.0.53:53           0.0.0.0:*                           -

me@me:/internal$ kill -HUP 21011

huangapple
  • 本文由 发表于 2020年1月7日 02:24:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/59617078.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定