get_osm function in osmar (R) gives SSL error

390 views Asked by At

Since a couple of months ago the following code run errorless

   library(osmar)
   src <- osmsource_api(url = "https://api.openstreetmap.org/api/0.6/")
   bb <- corner_bbox(13.3,40.79,13.5,40.81)
   ua <- get_osm(bb, source = src)

now it gives me the following error

"Error in function (type, msg, asError = TRUE) : error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version"

I failed to understand the issue. I try to run the code using two other computers with different version (older) of R but it still doesn't work.

Anyone has a possible solution?

Thanks in advance

1

There are 1 answers

0
noslomo On BEST ANSWER

I had the same issue. In detail the OSMAR package uses the package RCurl to load content which uses somehow an old encryption standard. You can fix the problem by building your "own" OSMAR package with small modifications.

import(curl)
  • add the package in the file R\get.R
#' @import RCurl
#' @import XML
#' @import gtools
#' @import methods
#' @import Curl
  • and exhange the method getURL from RCurl with the method curl from the package curl
get_osm_data.api <- function(source, what, ...) {
  request <- osm_request(source, what, ...)
  #response <- getURL(request, .encoding = "UTF-8")
  response <- paste(readLines(curl::curl(request)), collapse = "")
}
  • finally you can build the package. Restart RStudio / your R environment to use it.

This helped in my case. Best Andreas Weigert