NOAA天气REST API在使用curl请求时出错

3

我试图编写一个Python程序,使用NOAA的气候数据在线REST Web服务 (http://www.ncdc.noaa.gov/cdo-web/webservices/v2#data)。但是,我的请求响应中出现了错误。当我尝试使用命令行中的curl请求时,我输入了以下内容:

curl -H "token:<MYTOKEN>" http://www.ncdc.noaa.gov/cdo-web/api/v2/data?datasetid=GHCND&locationid=ZIP:22405&startdate=1999-10-05&enddate=1999-10-25

它返回以下响应:
[1] 24322
[2] 24323
[3] 24324
phil@philUbu:~$ <?xml version="1.0" encoding="UTF-8" standalone="yes"?><response><statusCode>400</statusCode><userMessage>There was an error with the request.</userMessage><developerMessage>Required parameter 'startdate' is missing.</developerMessage></response>
[1]   Done                    curl -H "token:..." http://www.ncdc.noaa.gov/cdo-web/api/v2/data?datasetid=GHCND
[2]-  Done                    locationid=ZIP:22405
[3]+  Done                    startdate=1999-10-05

不知何故它认为我缺少开始日期,但我已经包含了它,并且根据文档,它格式正确。有人有什么想法吗?

1个回答

1
在URL中的&可能被您的shell解析。请用单引号将其括起来:
 curl -H "token:<MYTOKEN>" 'http://www.ncdc.noaa.gov/cdo-web/api/v2/data?datasetid=GHCND&locationid=ZIP:22405&startdate=1999-10-05&enddate=1999-10-25'

问题已经解决了,但现在我得到了一个空响应“{ }”。 - ppeg34
没事了,这让我找到了正确的方向。非常感谢你的帮助! - ppeg34

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接