Home > Blockchain >  Question on Error in curl::curl_fetch_memory(url, handle = handle) in R
Question on Error in curl::curl_fetch_memory(url, handle = handle) in R

Time:10-08

Question: I try running the following code, but got an error.

Code:

library(httr)
url <- "http://geocoding.geo.census.gov/geocoder/locations/onelineaddress"
resp <-GET(url, query=list(address="1600 Pennsylvania Avenue, Washington DC",
                           benchmark=9,
                           format="json"))

json <- content(resp, type="application/json")
json$result$addressMatches[[1]]$coordinates

Error:

Error in curl::curl_fetch_memory(url, handle = handle) : 
  Failure when receiving data from the peer

The original code was provided by jlhoward, linked here httr GET operation unable to access JSON response

Since I don't have enough reputation to directly ask my question in the comment block, I create this new post and hope someone can help with. Can someone help to take a look? Your input is greatly appreciated!

CodePudding user response:

Couple of things:

  1. The protocol has changed to https from http (hence your error)
  2. The benchmark options have changed (at least in terms of the options)

Current benchmarks are:

  1. 4 for Public_AR_Current
  2. 8 for Public_AR_ACS2021
  3. 2020 for Public_AR_Census2020

An example update would thus look like:

library(httr)

url <- "https://geocoding.geo.census.gov/geocoder/locations/onelineaddress"
resp <-GET(url, query=list(address="1600 Pennsylvania Avenue, Washington DC",
                           benchmark=8,
                           format="json"))
json <- content(resp, type="application/json")
json$result$addressMatches[[1]]$coordinates
  • Related