weather.gov API过期的预测网格

问题描述 投票:0回答:1

我有一个程序,该程序使用weather.gov API Web Service提取预报链接列表,然后调用每个链接以提取并存储邮政编码的天气数据,可以根据用户在我们的主页上查看这些数据。邮政编码首选项。最近,我在错误日志中看到很多503错误,因此当我去检查它并使用Postman运行一些URL时,我得到以下响应:

{
    "correlationId": "36eb9a42-990d-4ca8-a24a-cd0c67985903",
    "title": "Forecast Grid Expired",
    "type": "https://api.weather.gov/problems/ForecastGridExpired",
    "status": 503,
    "detail": "The requested forecast grid was issued 2020-02-11T02:50:40+00:00 and has expired.",
    "instance": "https://api.weather.gov/requests/36eb9a42-990d-4ca8-a24a-cd0c67985903"
}

[不幸的是,我不知道当所请求的预测网格过期时这意味着什么,我也无法在其文档中找到任何内容。也许我错过了一些东西,或者我的代码中有一个导致此问题的问题。

这是一个Java程序,它使用javax.net.ssl.HttpsURLConnection和java.net.URL:

URL url = new URL("https://api.weather.gov/gridpoints/BOX/21,35/forecast");
HttpsURLConnection httpsConn = (HttpsURLConnection)url.openConnection();
httpsConn.setRequestMethod(HttpMethod.GET);
httpsConn.setRequestProperty("Content-Type", "application/json");
httpsConn.setConnectTimeout((1000 * 60));
httpsConn.setReadTimeout((1000 * 60));
StringBuffer response = getApiResponse(httpsConn, 0);

private StringBuffer getApiResponse(HttpsURLConnection httpsConn, int counter){
    StringBuffer response = new StringBuffer();
    try{
        BufferedReader in = new BufferedReader(new InputStreamReader(httpsConn.getInputStream()));
        String inputLine;
        while((inputLine = in.readLine()) != null){
            response.append(inputLine);
        }
        in.close();
    }catch(Exception e){
        counter++;
        errorLog.add("ERROR: " + e.getMessage());
        errorLog.add("Number of attempted calls: " + counter);
        if(counter < 5){
            response = getApiResponse(httpsConn, counter);
        }else{
            errorLog.add("Max attempts made for this API Call.");
        }
    }
    return response;
}

我将调用包装在一个函数中,该函数将尝试进行5次调用,正如我在构建此程序时注意到的那样,有时调用只是超时。我使用的url恰好是我遇到的问题之一,似乎涉及BOX的任何地方都导致了上述503错误。

还有其他人遇到过这样的问题-他们是如何解决的?

java weather-api
1个回答
0
投票

因此事实证明,这不是我们无法解决的问题。尽管503状态代码表示被调用的服务器无法处理该请求(并且我知道这不是我们的错),但收到的错误消息使我感到困惑,并且想知道它是否与我设置服务呼叫的方式。

© www.soinside.com 2019 - 2024. All rights reserved.