Skip to content

Commit

Permalink
Handle '429' errors from UK Met Office server
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Easterbrook <jim@jim-easterbrook.me.uk>
  • Loading branch information
jim-easterbrook committed Jul 18, 2016
1 parent 0c1e986 commit c05a4eb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/pywws/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = '16.07.0'
_release = '1355'
_commit = '29a7811'
__version__ = '16.07.1'
_release = '1356'
_commit = '0c1e986'
2 changes: 1 addition & 1 deletion src/pywws/services/metoffice.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ url = http://wow.metoffice.gov.uk/automaticreading
catchup = 7
interval = 890
use get = False
result = ['{}']
result = []
auth_type = None

[fixed]
Expand Down
26 changes: 16 additions & 10 deletions src/pywws/toservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# pywws - Python software for USB Wireless Weather Stations
# http://github.com/jim-easterbrook/pywws
# Copyright (C) 2008-15 pywws contributors
# Copyright (C) 2008-16 pywws contributors

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -447,6 +447,7 @@ def http_send_data(self, timestamp, prepared_data, ignore_last_update=False):
self.logger.debug(coded_data)
new_ex = self.old_ex
ex_info = []
success = False
try:
if self.use_get:
request = urllib2.Request(self.server + '?' + coded_data)
Expand All @@ -464,18 +465,21 @@ def http_send_data(self, timestamp, prepared_data, ignore_last_update=False):
self.old_response = response
for line in response:
log('rsp: %s', line.strip())
if len(response) == len(self.expected_result):
for actual, expected in zip(response, self.expected_result):
actual = actual.decode('utf-8')
for n, expected in enumerate(self.expected_result):
if n < len(response):
actual = response[n].decode('utf-8')
if not re.match(expected, actual):
break
else:
self.old_response = response
if not ignore_last_update:
self.set_last_update(timestamp)
return True
else:
self.old_response = response
if not ignore_last_update:
self.set_last_update(timestamp)
return True
return False
except urllib2.HTTPError, ex:
if ex.code == 429 and self.service_name == 'metoffice':
# UK Met Office server uses 429 to signal duplicate data
success = True
if sys.version_info >= (2, 7):
new_ex = '[%d]%s' % (ex.code, ex.reason)
else:
Expand All @@ -501,7 +505,9 @@ def http_send_data(self, timestamp, prepared_data, ignore_last_update=False):
extra = extra.strip()
if extra:
log('info: %s', extra)
return False
if success and not ignore_last_update:
self.set_last_update(timestamp)
return success

def next_data(self, catchup, live_data, ignore_last_update=False):
"""Get weather data records to upload.
Expand Down

0 comments on commit c05a4eb

Please sign in to comment.