【问题标题】:NOAA Weather REST API causes error when requesting with curl使用 curl 请求时,NOAA Weather REST API 会导致错误
【发布时间】:2015-07-07 19:13:17
【问题描述】:

我正在尝试使用 NOAA 的气候数据在线 REST Web 服务 (http://www.ncdc.noaa.gov/cdo-web/webservices/v2#data) 编写一个 python 程序。但是,我在请求响应中遇到了错误。从命令行尝试使用 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

由于某种原因,它认为我错过了开始日期,但我已将其包含在内,并且根据文档的格式正确。有人知道问题可能是什么吗?

【问题讨论】:

    标签: python shell rest curl noaa


    【解决方案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'
    

    【讨论】:

    • 解决了这个问题,但现在我得到一个空响应“{}”
    • 没关系,这让我走上了正轨。非常感谢您的帮助!
    猜你喜欢
    • 2020-10-29
    • 1970-01-01
    • 2014-12-15
    • 2021-10-16
    • 2018-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-06
    相关资源
    最近更新 更多