1

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!

1 Answer 1

1

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 option codes)

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
Sign up to request clarification or add additional context in comments.

2 Comments

Hi QHarr, thanks for pointing me the http porblem. Yes, https works. Also thank you for letting me know the updates of the benchmark codes. I really appreciate it!
you are most welcome

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.