Windows 7 R版本3.4.0 httr - 连接到人口普查Geocoder api时出现404错误

时间:2018-01-25 22:23:11

标签: r api geocode httr census

我正在运行以下代码,以便通过Census Geocoder api发送批处理文件。我查看了This QuestionAPI的文档。这对我没有帮助。我希望得到一些返回的数据,其中包含有关地址的信息......并且不会出现404错误。我似乎在返回调用时收到错误,我似乎正在发送数据好,但我无法检索数据?请帮我弄清楚为什么我收到错误。谢谢!

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()

1 个答案:

答案 0 :(得分:1)

实际上,如果您从http更改为https,您的代码将会正常工作。

您可能还想查看censusr包。