The http_error
(实际上来自图书馆httr
) 是一个非常简单的函数:它加载由字符 (http_error.character
),检索响应(http_error.response
)并最终查看响应代码(http_error.integer
)。如果响应代码是>=400
函数返回TRUE
否则FALSE
.
你的错误所说的是,你(或你的链中的任何函数)尝试调用http_error
on a simpleError
目的。我的猜测是您的防火墙设置阻止了该请求。因为请求被底层阻塞了httr::RETRY
(这是从oadoi_fetch
) 返回错误而不是正确的响应对象并且http_error
只看到这个错误对象并中断。
如果我在本地关闭我的代理(我可以通过它发出请求),我也会收到错误:
library(roadoi)
Sys.unsetenv(c("HTTP_PROXY", "HTTPS_PROXY"))
oadoi_fetch("10.1038/nature12373", email = "[email protected]")
# Error in UseMethod("http_error") :
# no applicable method for 'http_error' applied to an object of class
# "c('simpleError', 'error', 'condition')"
一旦我的代理设置正确,我就会得到
Sys.setenv(HTTPS_PROXY = my_proxy, HTTP_PROXY = my_proxy)
oadoi_fetch("10.1038/nature12373", email = "[email protected]")
# # A tibble: 1 x 16
# doi best_oa_location oa_locations data_standard is_oa genre journal_is_oa journal_is_in_d~ journal_issns journal_name publisher title year updated non_compliant authors
# <chr> <list> <list> <int> <lgl> <chr> <lgl> <lgl> <chr> <chr> <chr> <chr> <chr> <chr> <list> <list>
# 1 10.1038~ <tibble [1 x 10]> <tibble [4 x~ 2 TRUE journa~ FALSE FALSE 0028-0836,147~ Nature Springer ~ Nanometre-s~ 2013 2019-04-0~
如果问题确实出在代理上,我会尝试以下操作,这对我在公司 Windows 计算机上的操作有所帮助,但可能取决于您本地的 IT 设置:
## get the proxy settings
system("netsh winhttp show proxy")
Sys.setenv(HTTP_PROXY = <the proxy from netsh>, HTTPS_PROXY = <the proxy from netsh>)
实际上,您可以轻松地重现该错误:
httr::http_error(simpleError("Cannot reach the page"))
# Error in UseMethod("http_error") :
# no applicable method for 'http_error' applied to an object of class
# "c('simpleError', # 'error', 'condition')"