网页在浏览器中有效,但不能在R中使用:SSL证书问题:证书已过期

时间:2020-06-11 15:18:40

标签: r ssl rvest rcurl jsonlite

This网址可​​在浏览器中使用,提供一些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,尽管我使用的任何解决方案都不得使用浏览器自动化(硒),而必须使用jsonlite或rvest

2 个答案:

答案 0 :(得分:1)

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

原因

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

我能够通过this网站进行确认:

enter image description here

(不完美)解决方案

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

例如:

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

更改为

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

答案 1 :(得分:0)

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

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