【问题标题】:Webpage works in browser, but not from R: SSL certificate problem: certificate has expired网页在浏览器中工作,但不是来自 R:SSL 证书问题:证书已过期
【发布时间】:2020-06-11 15:18:40
【问题描述】:

This url 在浏览器中工作,提供一些 JSON 数据。

它在 R 中一直有效,直到最近,它现在返回:

library(jsonlite)
fromJSON("https://api.worldbank.org/v2/country?format=json")

# Error in open.connection(con, "rb") : 
#   SSL certificate problem: certificate has expired

library(rvest)
read_html("https://api.worldbank.org/v2/country?format=json")

# Error in open.connection(con, "rb") : 
#   SSL certificate problem: certificate has expired

到目前为止我所知道的

我不确定这是 API 方面的问题,还是 R 中的某个问题?

  • 似乎有一个类似的解决方案here,尽管我使用的任何解决方案都不能使用浏览器自动化 (selenium),而是必须使用 jsonlite 或 rvest

【问题讨论】:

  • 我无法复制 - 两条线都可以正常工作。它似乎不是API。也许尝试不同的连接方法?也许read_html(url("https://api.worldbank.org/v2/country?format=json", method= "libcurl"))
  • @AllanCameron 谢谢艾伦。您能说出您使用的是哪个版本的 R 吗?我在 4.0.1
  • 我现在使用的电脑运行的是旧版本:3.6.1
  • 有趣。 This 相关问题也在运行 R 4。但这可能是巧合。
  • 你尝试过不同的method = 看看是否修复了它史蒂夫?

标签: r ssl rvest rcurl jsonlite


【解决方案1】:

对于遇到类似问题的其他人

原因

网站所有者的 SSL 证书已过期。

我可以通过this 网站确认这一点:

(不完美)解决方案

由于我无法控制 url 的 SSL 证书,我只是将我使用的所有 url 从 https 更改为 http

例如:

"https://api.worldbank.org/v2/country?format=json"

更改为

"http://api.worldbank.org/v2/country?format=json"

【讨论】:

    【解决方案2】:

    我实际上也有这个问题......无论哪种方式我都无法访问它。我收到以下错误消息(当然,WDIcache() 也不起作用)

    Error in file(con, "r") : cannot open the connection to 'http://api.worldbank.org/indicators?per_page=25000&format=json'
    

    【讨论】:

    • 我认为世界银行已停用其 API 的第 1 版。 Checkout v2 of their API(我在 2 天前遇到了同样的问题)
    • Here 是我必须对 v2 进行更新的示例。希望有帮助
    • 尝试从 github 安装软件包,完全关闭 rstudio,重新打开并再次尝试。我可以看到here 提出的问题 - 我不确定它是否已经解决(有人说是,其他人没有),但有一种方法可以确定。我刚才跑了WDIcache(),它对我有用。从 github 安装 devtools::install_github("vincentarelbundock/WDI")
    • 我可以看到包现在在 CRAN 上是最新的。如果您重新安装该软件包,它现在应该可以在 1 分钟前运行 :-) - github.com/vincentarelbundock/WDI/issues/35 祝你好运!
    猜你喜欢
    • 1970-01-01
    • 2020-09-18
    • 2020-09-18
    • 1970-01-01
    • 2019-12-11
    • 2021-11-23
    • 2020-01-14
    • 1970-01-01
    • 2012-04-12
    相关资源
    最近更新 更多