首页 > 解决方案 > 通过任务计划程序运行批处理文件时,httpuv 无法启动 oauth 服务器

问题描述

我有一个启动 R 脚本的批处理文件:

"C:\Program Files\R\R-3.3.1\bin\x64\Rscript.exe" "C:\Folder\Script.R"

在这个 R 脚本中,我使用该gs_auth函数来获取我的身份验证令牌并在 R 会话中使用它。通过双击文件夹资源管理器中的批处理文件,我可以成功运行我的 R 脚本,并且一切运行良好。

当我设置任务计划程序任务来运行批处理文件时,我收到以下错误:

Error in httpuv::startServer(use$host, use$port, list(call = listen)) :
  Failed to create server
Calls: gs_title ... init_oauth2.0 -> oauth_authorize -> oauth_listener -> <Anonymous>
Execution halted

我已经尝试在任务计划程序中“以最高权限运行”,还输入了我的 Windows 密码,但似乎没有任何效果。

在加载令牌方面我有什么遗漏吗?


代码

注释掉的行在那里是因为它们显示了“烘焙”令牌的初始化步骤,以便我以后可以使用它。按照这里的步骤执行这些步骤。

##Need to run gs_auth line only because need to paste stuff in from IE
#token <- gs_auth(cache = FALSE)
#gd_token()
##Bake token to working directory
#saveRDS(token, file = "googlesheets_token.rds")

setwd("C:/Folder")
gs_auth(token = "googlesheets_token.rds")

for_gs <- gs_title("data_log")
for_gs_sheet <- gs_read(for_gs)

XML:

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2018-08-18T15:11:51.0347984</Date>
    <Author>abc-PC\User</Author>
    <URI>\ozb</URI>
  </RegistrationInfo>
  <Principals>
    <Principal id="Author">
      <UserId>S-1-5-21-2866463773-2659414307-4023886308-1002</UserId>
      <LogonType>InteractiveToken</LogonType>
    </Principal>
  </Principals>
  <Settings>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <Enabled>false</Enabled>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
  </Settings>
  <Triggers>
    <CalendarTrigger>
      <StartBoundary>2018-08-18T15:00:00</StartBoundary>
      <Repetition>
        <Interval>PT15M</Interval>
      </Repetition>
      <ScheduleByDay>
        <DaysInterval>1</DaysInterval>
      </ScheduleByDay>
    </CalendarTrigger>
  </Triggers>
  <Actions Context="Author">
    <Exec>
      <Command>"C:\Folder\run_it.bat"</Command>
    </Exec>
  </Actions>
</Task>

标签: rwindowsbatch-filetaskschedulerr-googlesheets

解决方案


推荐阅读