Search code examples
rsslrvestrcurljsonlite

Webpage works in browser, but not from R: SSL certificate problem: certificate has expired


This url works in the browser, providing some JSON data.

It worked from R until very recently, it now returns:

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

What I know so far

I am not sure if this is an issue on the API side, or somewhere in R?

  • There seems to be an analogous solution here, although any solution I use must not use browser automation (selenium), but instead must use either jsonlite or rvest

Solution

  • For anyone else who is having a similar issue

    The Cause

    The website owner had an expired SSL certificate.

    I was able to confirm this via this website:

    enter image description here

    (imperfect) Solution

    Since I have no control over the url's SSL certificate, I simply changed all the urls I was using from https to http.

    For example:

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

    changes to

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