From 84005eb86b3a4d7a1139fd99f24b4df1e5e29cf8 Mon Sep 17 00:00:00 2001
From: David Hoese <david.hoese@ssec.wisc.edu>
Date: Thu, 19 Mar 2020 11:03:32 -0500
Subject: [PATCH] Add wunderground upload timeout

---
 aosstower/level_00/influxdb.py | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/aosstower/level_00/influxdb.py b/aosstower/level_00/influxdb.py
index 338cdfa..0f8392f 100644
--- a/aosstower/level_00/influxdb.py
+++ b/aosstower/level_00/influxdb.py
@@ -246,12 +246,17 @@ def main():
                     print(url)
                 else:
                     LOG.info("Uploading new data to wunderground...")
-                    resp = requests.post(url)
-                    if resp.status_code != 200:
-                        warnings.warn('Data failed to upload to {0} with status code {1}: {2}'.format(
-                            url, resp.status_code, resp.text))
-                    else:
-                        LOG.info("Upload successful")
+                    try:
+                        resp = requests.post(url, timeout=15)
+                        if resp.status_code != 200:
+                            LOG.warning('Data failed to upload to {0} with status code {1}: {2}'.format(
+                                url, resp.status_code, resp.text))
+                        else:
+                            LOG.info("Upload successful")
+                    except requests.Timeout:
+                        LOG.error("Data upload to wunderground timed out", exc_info=True)
+                    except requests.ConnectionError:
+                        LOG.error("Data upload to wunderground had a connection error", exc_info=True)
 
             if args.sleep_interval:
                 time.sleep(args.sleep_interval)
-- 
GitLab