Windows 7 R 版本 3.4.0 httr -- 连接到人口普查地理编码器时出现 404 错误 api

Windows 7 R version 3.4.0 httr -- Get 404 error when connecting to census Geocoder api

我 运行 以下代码是为了通过人口普查地理编码器 api 发送批处理文件。我看了 and the Documentation for the API。这对我没有帮助。我希望得到一些包含地址信息的数据 return... 而不是 404 错误。我似乎在 return 调用中遇到错误,我似乎可以正常发送数据,但无法检索数据?请帮我弄清楚为什么会出现错误。谢谢!

require(httr)

req <- POST("http://geocoding.geo.census.gov/geocoder/geographies/addressbatch", 
        body = list(
          addressFile = upload_file("addresses.csv"),
          benchmark = "Public_AR_Census2010",
          vintage = "Census2010_Census2010"
        ), 
        encode = "multipart",
        verbose())
stop_for_status(req)
content(req)

我得到以下输出

-> POST /geocoder/geographies/addressbatch HTTP/1.1
-> Host: geocoding.geo.census.gov
-> User-Agent: libcurl/7.54.1 r-curl/2.8.1 httr/1.3.1
-> Accept-Encoding: gzip, deflate
-> Accept: application/json, text/xml, application/xml, */*
-> Content-Length: 615
-> Content-Type: multipart/form-data; boundary=------------------------c0a7880f53fb0ca4
-> 
>> --------------------------c0a7880f53fb0ca4
>> Content-Disposition: form-data; name="addressFile"; 
filename="addresses.csv"
>> Content-Type: text/csv
>> 

>> "Unique_ID","Street address","City","State","ZIP"
>> 1,"125 Worth Street","New York","NY","10013"
>> 2,"258 Broadway","New York","NY","10007"
>> 3,"8 Centre Street","New York","NY","10007"

>> 
>> --------------------------c0a7880f53fb0ca4
>> Content-Disposition: form-data; name="benchmark"
>> 
>> Public_AR_Census2010
>> --------------------------c0a7880f53fb0ca4
>> Content-Disposition: form-data; name="vintage"
>> 
>> Census2010_Census2010
>> --------------------------c0a7880f53fb0ca4--

<- HTTP/1.0 302 Found
<- Location: 
https://geocoding.geo.census.gov/geocoder/geographies/addressbatch
<- Server: BigIP
<- Connection: Keep-Alive
<- Content-Length: 0
<- 
-> GET /geocoder/geographies/addressbatch HTTP/1.0
-> Host: geocoding.geo.census.gov
-> User-Agent: libcurl/7.54.1 r-curl/2.8.1 httr/1.3.1
-> Accept-Encoding: gzip, deflate
-> Accept: application/json, text/xml, application/xml, */*
-> 
<- HTTP/1.1 404 Not Found
<- Cache-Control: no-cache, no-store, max-age=0
<- Connection: close
<- Date: Thu, 25 Jan 2018 22:03:01 GMT
<- Pragma: no-cache
<- Content-Type: application/json
<- Expires: Wed, 31 Dec 1969 23:59:59 GMT
<- Content-Language: en-US
<- Vary: Origin
<- 
> stop_for_status(req)
Error: Not Found (HTTP 404).
> content(req)
named list()

实际上,如果您从 http 更改为 https,您的代码将起作用。

您可能还想查看 censusr 包。