Add timeout for slow/no response from NWS servers

This commit is contained in:
Dan Srebnick 2018-02-20 14:18:36 -05:00
parent 6df0666323
commit 38d066b26e
4 changed files with 45 additions and 4 deletions

View File

@ -1,5 +1,5 @@
Package: noaacap Package: noaacap
Version: 0.8 Version: 0.9
Section: hamradio Section: hamradio
Priority: extra Priority: extra
Maintainer: Dan Srebnick <k2dls at k2dls.net> Maintainer: Dan Srebnick <k2dls at k2dls.net>

View File

@ -6,7 +6,7 @@
## ##
## See /usr/local/share/noaacap/CHANGELOG for change history ## See /usr/local/share/noaacap/CHANGELOG for change history
## ##
version = "0.8" version = "0.9"
import sys import sys
import pytz import pytz
@ -87,7 +87,12 @@ except:
url = 'https://alerts.weather.gov/cap/wwaatmget.php?x=' + myZone + '&y=0' url = 'https://alerts.weather.gov/cap/wwaatmget.php?x=' + myZone + '&y=0'
r = requests.get(url) try:
r = requests.get(url, timeout=2)
except requests.exceptions.Timeout:
log.error("Timeout exception requesting " + url)
ErrExit()
if r.status_code != 200: if r.status_code != 200:
log.error(str(r.status_code) + " " + url) log.error(str(r.status_code) + " " + url)
ErrExit() ErrExit()
@ -252,7 +257,12 @@ for i in range(0, count):
t = t + chr(s+61) t = t + chr(s+61)
# Pull specific alert to get compressed UGC zones # Pull specific alert to get compressed UGC zones
rs = requests.get(entries[i].id.string) try:
rs = requests.get(entries[i].id.string, timeout=2)
except requests.exceptions.Timeout:
log.error("Timeout exception requesting " + url)
ErrExit()
if rs.status_code != 200: if rs.status_code != 200:
log.error(str(rs.status_code) + " " + rs) log.error(str(rs.status_code) + " " + rs)
ErrExit() ErrExit()

View File

@ -0,0 +1,27 @@
*** /dev/null
--- /dev/null
***************
*** 9
- version = "0.9"
--- 9 -----
+ version = "0.8"
***************
*** 90,95
- try:
- r = requests.get(url, timeout=2)
- except requests.exceptions.Timeout:
- log.error("Timeout exception requesting " + url)
- ErrExit()
-
--- 90 -----
+ r = requests.get(url)
***************
*** 260,265
- try:
- rs = requests.get(entries[i].id.string, timeout=2)
- except requests.exceptions.Timeout:
- log.error("Timeout exception requesting " + url)
- ErrExit()
-
--- 255 -----
+ rs = requests.get(entries[i].id.string)

View File

@ -1,5 +1,9 @@
noaacap changelog noaacap changelog
## ##
Version: 0.9
Release: February 20, 2018
Added timeout for non/slow response of NWS servers
##
Version: 0.8 Version: 0.8
Release: January 29, 2018 Release: January 29, 2018
Added added handling for expired alerts Added added handling for expired alerts