roadoi中的UseMethod(“http_error”)出错

问题描述 投票:3回答:1

我正在尝试使用roadoi从R访问Unpaywall,但无论我尝试查询什么,我都得到了这样的响应:

UseMethod(“http_error”)中的错误:没有适用于“http_error”的方法应用于类“c('simpleError','error','condition')的对象”

运行methods(http_error)给了我这个:

[1] http_error.character* http_error.integer*   http_error.response*

这可能是由于我在机构防火墙后面造成的吗? (即使如此,这似乎很奇怪,这将是回应......)

有办法解决吗?

r http-error roadoi unpaywall
1个回答
3
投票

http_error(实际上来自库httr)是一个非常简单的函数:它加载由字符(http_error.character)给出的url,检索响应(http_error.response)并最终查看响应代码(http_error.integer)。如果响应代码是>=400,则函数返回TRUE,否则返回FALSE

你的错误说的是,你(或链中的任何函数)试图在http_error对象上调用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')"
© www.soinside.com 2019 - 2024. All rights reserved.