【问题标题】:RSelenium rsDriver peer SSL certificate issueRSelenium rsDriver 对等 SSL 证书问题
【发布时间】:2017-07-25 03:58:43
【问题描述】:

我正在尝试学习使用 RSelenium。我只是试图使用 rsDriver 启动服务器。我只是试图运行下面的代码并得到以下错误:

rD <- rsDriver()
checking Selenium Server versions:
BEGIN: PREDOWNLOAD
Error in open.connection(con, "rb") : 
  Peer certificate cannot be authenticated with given CA certificates

我搜索了堆栈溢出,发现我们可以使用下面的方法为 rsDriver 提供选项,但我仍然遇到错误:

my_extra <- list("--ignore-ssl-errors=true", "--ssl-protocol=tlsv1", "--web-security=no")
rs <- rsDriver(extraCapabilities = my_extra)
checking Selenium Server versions:
BEGIN: PREDOWNLOAD
Error in open.connection(con, "rb") : 
  Peer certificate cannot be authenticated with given CA certificates

我还有什么遗漏的吗?

对于 httr::GET 功能,我可以使用以下方法绕过 SSL 证书:

set_config(config(ssl_verifypeer=0L)). 

但此方法不适用于 RSelenium::rsDriver。

这是我的系统规格: 我的操作系统:Microsoft Windows 10

R version 3.4.1 (2017-06-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] RCurl_1.95-4.8  bitops_1.0-6    httr_1.2.1      wdman_0.2.2    
[5] RSelenium_1.7.1

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.12     XML_3.98-1.9     binman_0.1.0     assertthat_0.2.0
 [5] R6_2.2.2         jsonlite_1.5     semver_0.2.0     curl_2.7        
 [9] tools_3.4.1      yaml_2.1.14      compiler_3.4.1   caTools_1.17.1  
[13] openssl_0.9.6

【问题讨论】:

  • 我试过这个命令:httr::with_config(config(ssl_verifypeer=0L),wdman::selenium(retcommand=TRUE))。但它仍然不起作用。完全相同的错误:对等证书无法使用给定的 CA 证书进行身份验证。有没有其他启动服务器的方法?也许使用其他方法可以通过“忽略 SSL 证书”命令?
  • 问题在于jsonlite::fromJSON。底层包curl 需要传递ssl_verifypeer 参数。在给出的问题中,您可以通过模拟函数来做到这一点。

标签: r selenium ssl connection certificate


【解决方案1】:

rsDriver 使用 binman 包来处理相关二进制文件的下载。 selenium 项目在 https://www.googleapis.com/storage/v1/b/selenium-release/o 的 JSON 文件中列出了它的版本 如果您尝试,您应该会遇到同样的问题:

jsonlite::fromJSON("https://www.googleapis.com/storage/v1/b/selenium-release/o")

您可以使用类似 mock 的相关 curl 资金:

my_new_handle <- function(...){
  print("mocking")
  h <- .Call(curl:::R_new_handle, PACKAGE = "curl")
  curl:::handle_setopt(h, ..., ssl_verifypeer = FALSE)
  h
}
testthat::with_mock(
  `curl::new_handle` = my_new_handle,
  {
    selCommand <- httr::with_config(config(ssl_verifypeer=0L),wdman::selenium(‌​retcommand=TRUE))
  }
)

【讨论】:

  • 你是对的。我确实遇到了与 jsonlite 相同的问题。但是,我设法使用您提供的 set 函数下载了 seleniumserver、chromedriver、firefoxdriver 和 phantomjs。我是否必须继续使用模拟命令以及 rsDriver?
  • 下载驱动程序后,您可以将check = FALSE 设置为rsDriver 中的参数,它不应该检查更新的驱动程序。
  • 我输入了 check = FALSE 但 rsDriver 仍然检查 selenium 服务器版本。 (我知道我原来的问题有点离题。但我仍然只是想让 rsDriver 工作。)
  • 检查参数在 CRAN 上的 RSelenium 版本中被错误地传递。使用来自 github 的开发版本。 devtools::install_github("ropensci/RSelenium")。见github.com/ropensci/RSelenium/issues/123
  • 谢谢!我下载了这个包,它确实有效。但是当我尝试启动 rD [.data.frame(as.data.frame(x[["client"]]$sessionInfo), c("browserName" , : 选择了未定义的列。很抱歉用这么多问题打扰您,但感觉让这条线工作有点困难。
猜你喜欢
  • 1970-01-01
  • 2015-05-29
  • 1970-01-01
  • 1970-01-01
  • 2020-10-14
  • 1970-01-01
  • 2018-07-20
  • 2012-02-07
  • 1970-01-01
相关资源
最近更新 更多