Author Topic: Error: no forecast data was found in JSON from api.weather.gov  (Read 1318 times)

0 Members and 1 Guest are viewing this topic.

Offline soundpassion

  • Member
  • *
  • Posts: 10
Hi guys,

here we are again with another weird issue that i'm not able to figure it out, thank you in advance to all the good Samaritan that will help me.
Suddenly i'm not getting anymore the weather forecast on the website under "Previsioni" column of ajax-dashboard.

http://meteorsago.altervista.org/swpi/

and i get the error "Error: no forecast data was found in JSON from api.weather.gov"
The error comes from a check executed on the WC-forecast.php file at line 589 ish

I enabled the debug available around line 454 and i got this:

Code: [Select]
 <!-- WC-forecast.php (ML) Version 1.05 - 01-Jan-2021 on PHP 5.6.40 -->
<!-- autoSetTemplate using narrow aspect. -->
<!-- WC_API Raw LatLong='37.27465,-122.02295' -->
<!-- WC API New URL='https://api.weather.com/v3/wx/forecast/daily/5day?format=json&units=m&language=it-IT&apiKey=<removed>&geocode=37.27465,-122.02295' -->
<!-- loading from ./cache/WC-forecast-json-0-m-it.txt (5311 bytes) -->
<!-- using charsetInput='UTF-8' charsetOutput='ISO-8859-1' doIconv='1' doRTL='' -->
<!-- processing JSON entries for forecast -->
<!-- rawJSON size is 5307 bytes -->
<!-- WC_prepareJSON: Success. Valid UTF-8. -->
<!-- json_decode returns - Syntax error, malformed JSON -->

using chatgpt i've been able to fix the syntax error removing the header curl parameter from true to false:

Code: [Select]
curl_setopt($ch, CURLOPT_HEADER, false);
and applying this before "$rawJSON = WC_prepareJSON($rawJSON);" around line 447:

Code: [Select]
$rawJSON = trim($response);
Code: [Select]
<!-- WC-forecast.php (ML) Version 1.04 - 22-Mar-2019 on PHP 5.6.40 -->
<!-- autoSetTemplate using narrow aspect. -->
<!-- WC_API Raw LatLong='45.92670,12.43850' -->
<!-- WC API New URL='https://api.weather.com/v3/wx/forecast/daily/5day?format=json&units=m&language=it-IT&apiKey=<removed>&geocode=45.92670,12.43850' -->
<!-- loading from ./cache/WC-forecast-json-0-m-it.txt (5634 bytes) -->
<!-- using charsetInput='UTF-8' charsetOutput='ISO-8859-1' doIconv='1' doRTL='' -->
<!-- processing JSON entries for forecast -->
<!-- rawJSON size is 5630 bytes -->
<!-- WC_prepareJSON: Success. Valid UTF-8. -->
<!-- json_decode returns - No errors -->

but i'm still getting the error object of this thread, so the header shouldn't be the main issue.
The JSON looks the same as some days ago except for the header but cleaning it with the fixes above i can exclude this as an issue.

Code: [Select]
{"calendarDayTemperatureMax":[15,19,20,22,17,15],"calendarDayTemperatureMin":[5,6,9,10,12,12],"dayOfWeek":["mercoledì","giovedì","venerdì","sabato","domenica","lunedì"],"expirationTimeUtc":[1744172392,1744172392,1744172392,1744172392,1744172392,1744172392],"moonPhase":["Gibbosa crescente","Gibbosa crescente","Gibbosa crescente","Plenilunio","Plenilunio","Gibbosa calante"],"moonPhaseCode":["WXG","WXG","WXG","F","F","WNG"],"moonPhaseDay":[11,12,13,14,15,16],"moonriseTimeLocal":["2025-04-09T16:22:20+0200","2025-04-10T17:28:28+0200","2025-04-11T18:32:39+0200","2025-04-12T19:37:55+0200","2025-04-13T20:43:17+0200","2025-04-14T21:50:44+0200"],"moonriseTimeUtc":[1744208540,1744298908,1744389159,1744479475,1744569797,1744660244],"moonsetTimeLocal":["2025-04-09T05:21:34+0200","2025-04-10T05:37:17+0200","2025-04-11T05:51:47+0200","2025-04-12T06:06:08+0200","2025-04-13T06:21:37+0200","2025-04-14T06:39:28+0200"],"moonsetTimeUtc":[1744168894,1744256237,1744343507,1744430768,1744518097,1744605568],"narrative":["Poco nuvoloso. Massime da 14 a 16° C e minime da 5 a 7° C.","Poco nuvoloso. Massime da 18 a 20° C e minime da 8 a 10° C.","Quasi sereno. Massime da 19 a 21° C e minime da 9 a 11° C.","Poco nuvoloso. Massime da 21 a 23° C e minime da 11 a 13° C.","Acquazzoni nel pomeriggio. Massime da 16 a 18° C e minime da 11 a 13° C.","Pioggia. Massime da 14 a 16° C e minime da 11 a 13° C."],"qpf":[0.0,0.0,0.0,0.0,4.46,38.18],"qpfSnow":[0.0,0.0,0.0,0.0,0.0,0.0],"sunriseTimeLocal":["2025-04-09T06:34:40+0200","2025-04-10T06:32:48+0200","2025-04-11T06:30:57+0200","2025-04-12T06:29:07+0200","2025-04-13T06:27:17+0200","2025-04-14T06:25:28+0200"],"sunriseTimeUtc":[1744173280,1744259568,1744345857,1744432147,1744518437,1744604728],"sunsetTimeLocal":["2025-04-09T19:49:38+0200","2025-04-10T19:50:56+0200","2025-04-11T19:52:14+0200","2025-04-12T19:53:32+0200","2025-04-13T19:54:50+0200","2025-04-14T19:56:08+0200"],"sunsetTimeUtc":[1744220978,1744307456,1744393934,1744480412,1744566890,1744653368],"temperatureMax":[15,19,20,22,17,15],"temperatureMin":[6,9,10,12,12,12],"validTimeLocal":["2025-04-09T07:00:00+0200","2025-04-10T07:00:00+0200","2025-04-11T07:00:00+0200","2025-04-12T07:00:00+0200","2025-04-13T07:00:00+0200","2025-04-14T07:00:00+0200"],"validTimeUtc":[1744174800,1744261200,1744347600,1744434000,1744520400,1744606800],"daypart":[{"cloudCover":[58,37,45,31,25,47,36,56,87,96,100,100],"dayOrNight":["D","N","D","N","D","N","D","N","D","N","D","N"],"daypartName":["Oggi","Stasera","Domani","Domani sera","venerdì","Venerdì notte","sabato","Sabato notte","domenica","Domenica notte","lunedì","Lunedì notte"],"iconCode":[30,29,30,29,34,29,30,29,39,11,12,12],"iconCodeExtend":[3000,2900,3000,2900,3400,2900,3000,2900,7103,1100,1200,1200],"narrative":["Poco nuvoloso. Massime 15° C. Venti da SE, da 10 a 15 km/h.","Poco nuvoloso. Minime 6° C. Venti da NE variabili.","Poco nuvoloso. Massime 19° C. Venti da S, da 10 a 15 km/h.","Poco nuvoloso. Minime 9° C. Venti da NNE variabili.","Quasi sereno. Massime 20° C. Venti da SSE, da 10 a 15 km/h.","Poco nuvoloso. Minime 10° C. Venti da NE variabili.","Poco nuvoloso. Massime 22° C. Venti da SE, da 10 a 15 km/h.","Poco nuvoloso. Minime 12° C. Venti da NE variabili.","Acquazzoni nel pomeriggio. Massime 17° C. Venti da ESE variabili. Prob. pioggia: 40%.","Acquazzoni. Minime 12° C. Venti da ENE variabili. Prob. pioggia: 70%.","Pioggia. Massime 15° C. Venti da ENE, da 10 a 15 km/h. Prob. pioggia: 80%. Piovosità di circa 12 mm.  Possibilità di forti precipitazioni piovose locali.","Pioggia. Minime 12° C. Venti da NE, da 10 a 15 km/h. Prob. pioggia: 80%. Piovosità di circa 25 mm.  Possibilità di forti precipitazioni piovose locali."],"precipChance":[2,24,5,6,5,6,4,20,39,69,83,78],"precipType":["rain","rain","rain","rain","rain","rain","rain","rain","rain","rain","rain","rain"],"qpf":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.07,3.4,18.48,19.69],"qpfSnow":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"qualifierCode":[null,null,null,null,null,null,null,null,null,null,"Q5050","Q5050"],"qualifierPhrase":[null,null,null,null,null,null,null,null,null,null,"Possibilità di forti precipitazioni piovose locali.","Possibilità di forti precipitazioni piovose locali."],"relativeHumidity":[64,82,64,80,70,85,63,83,80,94,96,98],"snowRange":["","","","","","","","","","","",""],"temperature":[15,6,19,9,20,10,22,12,17,12,15,12],"temperatureHeatIndex":[15,14,19,16,20,17,22,19,17,16,15,15],"temperatureWindChill":[6,6,6,9,9,10,10,12,12,12,12,12],"thunderCategory":[null,null,null,null,null,null,null,null,null,null,null,null],"thunderIndex":[0,0,0,0,0,0,0,0,0,0,0,0],"uvDescription":["Moderato","Basso","Moderato","Basso","Moderato","Basso","Moderato","Basso","Basso","Basso","Basso","Basso"],"uvIndex":[4,0,5,0,5,0,5,0,2,0,2,0],"windDirection":[143,41,186,31,160,46,143,50,108,67,59,52],"windDirectionCardinal":["SE","NE","S","NNE","SSE","NE","SE","NE","ESE","ENE","ENE","NE"],"windPhrase":["Venti da SE, da 10 a 15 km/h.","Venti da NE variabili.","Venti da S, da 10 a 15 km/h.","Venti da NNE variabili.","Venti da SSE, da 10 a 15 km/h.","Venti da NE variabili.","Venti da SE, da 10 a 15 km/h.","Venti da NE variabili.","Venti da ESE variabili.","Venti da ENE variabili.","Venti da ENE, da 10 a 15 km/h.","Venti da NE, da 10 a 15 km/h."],"windSpeed":[11,7,12,8,11,7,10,7,10,8,12,10],"wxPhraseLong":["Poco nuvoloso","Poco nuvoloso","Poco nuvoloso","Poco nuvoloso","Prevalentemente soleggiato","Poco nuvoloso","Poco nuvoloso","Poco nuvoloso","Acquazzoni PM","Acquazzoni","Pioggia","Pioggia"],"wxPhraseShort":["","","","","","","","","","","",""]}]}
The problem I think is probably related to the count of "$WCforecasticons" that probably is zero.

Do you guys have any suggestion about it? Did somebody faced this issue before?

Thank you so much

Andrea
« Last Edit: April 09, 2025, 05:26:29 AM by soundpassion »

Offline wvdkuil

  • Wim van der kuil
  • Forecaster
  • *****
  • Posts: 2073
    • My PWS at Leuven Belgium Europe
Re: Error: no forecast data was found in JSON from api.weather.gov
« Reply #1 on: April 09, 2025, 04:46:01 AM »
There is a new version of the script:  Version 1.05 - 01-Jan-2021 - fix for PoP icon displays
More info: https://saratoga-weather.org/scripts-WCforecast.php#WCforecast

I tested that version with only minimal modifications for
-> your area, your language, UTF-8 character-set and no drop-down
It works OK, see attachments

Succes, wim

Code: [Select]
<!-- WC-forecast.php (ML) Version 1.05 - 01-Jan-2021 on PHP 8.2.0 -->
<!-- WC_API Raw LatLong='45.92670,12.43850' -->
<!-- WC API New URL='https://api.weather.com/v3/wx/forecast/daily/5day?format=json&units=m&language=it-IT&apiKey=API-key-removed&geocode=45.92670,12.43850' -->
<!-- loading from https://api.weather.com/v3/wx/forecast/daily/5day?format=json&units=m&language=it-IT&apiKey=API-key-removed&geocode=45.92670,12.43850. -->
<!-- curl fetching 'https://api.weather.com/v3/wx/forecast/daily/5day?format=json&units=m&language=it-IT&apiKey=API-key-removed&geocode=45.92670,12.43850' -->
<!-- HTTP stats:  RC=200 dest=23.72.252.49 port=443 (from sce=192.168.0.159)
      Times: dns=0.002 conn=0.028 pxfer=0.102 get=0.060 total=0.162 secs -->
<!-- RC=200, bytes=6104 -->
<!-- saved cache to ./WC-forecast-json-0-m-it.txt (6104 bytes) -->
<!-- using charsetInput='UTF-8' charsetOutput='UTF-8' doIconv='' doRTL='' -->
<!-- processing JSON entries for forecast -->
<!-- rawJSON size is 5627 bytes -->
<!-- WC_prepareJSON: Success. Valid UTF-8. -->
<!-- json_decode returns  - No errors -->
<!-- replace icon '30' with 'sct.jpg' pop=0 -->
. . .


Offline soundpassion

  • Member
  • *
  • Posts: 10
Re: Error: no forecast data was found in JSON from api.weather.gov
« Reply #2 on: April 09, 2025, 06:18:34 AM »
Hi  [tup],

thank you for the answer.
I replaced the file with the new version but the error is still the same.
one question, if you don't disable the drop-down does the page work for you?
If no could you please tell me where to disable it? thanks

I noticed that you use PHP 8.2, could it be the root cause for me?

Offline wvdkuil

  • Wim van der kuil
  • Forecaster
  • *****
  • Posts: 2073
    • My PWS at Leuven Belgium Europe
Re: Error: no forecast data was found in JSON from api.weather.gov
« Reply #3 on: April 09, 2025, 06:59:08 AM »
Hi  [tup],

one question, if you don't disable the drop-down does the page work for you?
If no could you please tell me where to disable it? thanks

I noticed that you use PHP 8.2, could it be the root cause for me?

Disabled the dropdown by commenting the array-items.
Seems you commented the array definition, that generates a PHP error.
Code: [Select]
$WCforecasts = array(
 // Location name to display|lat,long  (separated by | character)
/*'Saratoga, CA, USA|37.27465,-122.02295',
'Auckland, NZ|-36.910,174.771', // Awhitu, Waiuku New Zealand
'Assen, NL|53.02277,6.59037',
. . .
'Tahoe Vista, CA, USA|39.2403,-120.0528',
'Auburn, CA, USA|38.8962,-121.0789', */
);

I tested with PHP 8.2, works OK.

I add the zip of my test version
1. change line 68 to your API-key
2. Rename your version to WC-forecast_old.php or similar name
3. Rename unzipped version to WC-forecast.php

Should work out of the box.

Succes,
Wim

Offline soundpassion

  • Member
  • *
  • Posts: 10
Re: Error: no forecast data was found in JSON from api.weather.gov
« Reply #4 on: April 09, 2025, 08:34:56 AM »
Hi,

Thanks for the help man, i appreciate it.
i replaced the file as suggested and added the api key.
I'm still getting the error.

Regarding the PHP, once i change it to any version newer than 5.6 I get a blank screen, I debugged it and found some deprecated code and a warning that i fixed but the blank screen persist.

Offline wvdkuil

  • Wim van der kuil
  • Forecaster
  • *****
  • Posts: 2073
    • My PWS at Leuven Belgium Europe
Re: Error: no forecast data was found in JSON from api.weather.gov
« Reply #5 on: April 09, 2025, 09:21:52 AM »
Hi,

Thanks for the help man, i appreciate it.
i replaced the file as suggested and added the api key.
I'm still getting the error.

Regarding the PHP, once i change it to any version newer than 5.6 I get a blank screen, I debugged it and found some deprecated code and a warning that i fixed but the blank screen persist.

i tested with PHP8.2.0 and 8.2.14
No errors with the script.

But you added a line with an error in it.
 
Code: [Select]
$rawJSON = trim($response);There is no $response item so it results in a fatal PHP error

Just check the script running without any other Saratoga script, no images, PHP8.2.14, full error reporting.
https://pwswd.be/_test.php?test=WC-forecast2.php&debug=Y

Or in default mode
https://pwswd.be/WC-forecast2.php
 
No errors, no problems. Correct html

Succes,
Wim


Wim

« Last Edit: April 09, 2025, 09:24:10 AM by wvdkuil »

Offline wvdkuil

  • Wim van der kuil
  • Forecaster
  • *****
  • Posts: 2073
    • My PWS at Leuven Belgium Europe
Re: Error: no forecast data was found in JSON from api.weather.gov
« Reply #6 on: April 09, 2025, 09:38:09 AM »
You should not remove the headers as you did in your CURL code
The script uses that information, and it uses code to skip the headers.
But as there are no headers in your data-file, the json data is compromised.

line 872 should read:
Code: [Select]
   curl_setopt($ch, CURLOPT_HEADER, true);                      // include header information

This is the code on line 440 to split headers and content
Code: [Select]
$Status .= "<!-- processing JSON entries for forecast -->\n";
  $i = strpos($html,"\r\n\r\n");
  $headers = substr($html,0,$i-1);
  $content = substr($html,$i+4);
Succes,
Wim
« Last Edit: April 09, 2025, 09:46:55 AM by wvdkuil »

Offline soundpassion

  • Member
  • *
  • Posts: 10
Re: Error: no forecast data was found in JSON from api.weather.gov
« Reply #7 on: April 09, 2025, 09:49:03 AM »
Hi,

thank you.
I'm trying anything to fix it... sorry.
Maybe i found the issue, the json i'm getting has something more than yours on top.

Offline wvdkuil

  • Wim van der kuil
  • Forecaster
  • *****
  • Posts: 2073
    • My PWS at Leuven Belgium Europe
Re: Error: no forecast data was found in JSON from api.weather.gov
« Reply #8 on: April 09, 2025, 09:58:35 AM »
Hi,

thank you.
I'm trying anything to fix it... sorry.
Maybe i found the issue, the json i'm getting has something more than yours on top.

Now that is new to me and it is certainly cause of the problems.

Maybe a more proficient HTML expert can tell us how to get rid of that info.

Regards,
Wim

Offline soundpassion

  • Member
  • *
  • Posts: 10
Re: Error: no forecast data was found in JSON from api.weather.gov
« Reply #9 on: April 09, 2025, 10:38:19 AM »
I made it, querying chatgpt like crazy.

i asked to remove the first four lines... but at the end the file it's still the same.
Probably during the process of the JSON those line are not present than I fixed the issue.

This is the code I used, I don't know if it's correct, clean or whatever, what i know is that now the forecast works  :grin: :grin: :grin:

BEFORE
Code: [Select]
$Status .= "<!-- processing JSON entries for forecast -->\n";
  $i = strpos($html,"/\r\n|\n|\r/");
  $headers = substr($html,0,$i-1);
  $content = substr($html,$i+4);

  $rawJSON = $content;
  $Status .= "<!-- rawJSON size is ".strlen($rawJSON). " bytes -->\n";
  $rawJSON = WC_prepareJSON($rawJSON);
  $JSON = json_decode($rawJSON,true); // get as associative array
  $Status .= WC_decode_JSON_error();
  if($doDebug) {$Status .= "<!-- JSON\n".print_r($JSON,true)." -->\n"; }

AFTER
Code: [Select]
// Split lines using \r\n to handle HTTP header endings
$lines = preg_split("/\r\n|\n|\r/", $html);

// Remove the first 4 lines
$cleaned = array_slice($lines, 4);

// Rebuild the content string
$content = implode("\n", $cleaned);

// Trim until the first JSON brace just to be safe
$pos = strpos($content, '{');
$rawJSON = ($pos !== false) ? substr($content, $pos) : '';

$Status .= "<!-- rawJSON size is " . strlen($rawJSON) . " bytes -->\n";
$rawJSON = WC_prepareJSON($rawJSON);
$JSON = json_decode($rawJSON, true);
$Status .= WC_decode_JSON_error();
if ($doDebug) {
    $Status .= "<!-- JSON\n" . print_r($JSON, true) . " -->\n";
}

thank you Wim for driving me to the solution.