【问题标题】:Question on Error in curl::curl_fetch_memory(url, handle = handle) in R关于 R 中 curl::curl_fetch_memory(url, handle = handle) 中的错误的问题
【发布时间】:2021-11-26 16:45:49
【问题描述】:

问题:我尝试运行以下代码,但出现错误。

代码:

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 in curl::curl_fetch_memory(url, handle = handle) : 
  Failure when receiving data from the peer

原代码由jlhoward提供,链接在这里httr GET operation unable to access JSON response

由于我没有足够的声望直接在评论区提出我的问题,所以我创建了这个新帖子,希望有人能提供帮助。有人可以帮忙看看吗?非常感谢您的意见!

【问题讨论】:

    标签: r api url httr


    【解决方案1】:

    几件事:

    1. 协议已从 http 更改为 https(因此出现错误)
    2. 基准选项已更改(至少在选项代码方面)

    目前的基准是:

    1. 4 代表 Public_AR_Current
    2. 8 代表 Public_AR_ACS2021
    3. 2020 年 Public_AR_Census2020

    因此,更新示例如下所示:

    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
    

    【讨论】:

    • 您好 QHarr,感谢您向我指出 http 问题。是的,https 有效。也感谢您让我知道基准代码的更新。我真的很感激!
    • 不客气
    猜你喜欢
    • 2017-12-14
    • 1970-01-01
    • 2020-03-31
    • 2020-09-20
    • 2015-10-22
    • 2020-03-03
    • 2016-11-11
    • 2018-12-18
    • 2018-12-26
    相关资源
    最近更新 更多