Error in UseMethod(“http_error”) in roadoi

为君一笑 提交于 2020-01-04 01:38:07

问题


I'm trying out roadoi to access Unpaywall from R, but no matter what I try to query for, I'm getting this response:

Error in UseMethod("http_error") : no applicable method for 'http_error' applied to an object of class "c('simpleError', 'error', 'condition')"

Running methods(http_error) gives me this:

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

Could this be caused by me being behind an institutional firewall? (even so, it seems weird that this would be the response...)

Is there a way around it?


回答1:


The http_error (actually from library httr) is a very simple function: it loads an url given by a character (http_error.character), retrieves the response (http_error.response) and ultimately looks at the response code (http_error.integer). If the response code is >=400 the function returns TRUE otherwise FALSE.

What your error says, is that you (or any function in your chain) tries to call http_error on a simpleError object. My guess is that your firewall settings block the request. Because the request is blocked the underlying httr::RETRY (which is called from oadoi_fetch) returns an error instead of a proper response object and http_error sees just this error object and breaks.

If I locally switch off my proxy (through which I can make requests) I also get an error:

library(roadoi)
Sys.unsetenv(c("HTTP_PROXY", "HTTPS_PROXY"))
oadoi_fetch("10.1038/nature12373", email = "name@whatever.com")
# Error in UseMethod("http_error") : 
#   no applicable method for 'http_error' applied to an object of class
#   "c('simpleError', 'error', 'condition')"

As soon as my proxy is set properly I get

Sys.setenv(HTTPS_PROXY = my_proxy, HTTP_PROXY = my_proxy)
oadoi_fetch("10.1038/nature12373", email = "name@whatever.com")
# # 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~

If the problem lies indeed with the proxy, I would try the following, which helped me on my corporate Windows machine, but may be dependent on your local IT setting:

## get the proxy settings
system("netsh winhttp show proxy")
Sys.setenv(HTTP_PROXY = <the proxy from netsh>, HTTPS_PROXY = <the proxy from netsh>)

Actually, you can reproduce the error easily:

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')"


来源:https://stackoverflow.com/questions/55244646/error-in-usemethodhttp-error-in-roadoi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!