Skip to content

Commit

Permalink
Use 'repr' instead of 'str' in exception handling
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 Sep 18, 2018
1 parent c044edd commit 15bd807
Show file tree
Hide file tree
Showing 17 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/pywws/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = '18.9.0'
_release = '1635'
_commit = '7f2fa93'
_release = '1636'
_commit = 'c044edd'
2 changes: 1 addition & 1 deletion src/pywws/examples/modules/aws_api_gw_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def upload_data(self, session, prepared_data={}):
rsp = session.get(self.params['api url'], params=prepared_data,
timeout=60)
except Exception as ex:
return False, str(ex)
return False, repr(ex)
if rsp.status_code != 200:
return False, 'http status: {:d}'.format(rsp.status_code)
rsp = rsp.json()
Expand Down
2 changes: 1 addition & 1 deletion src/pywws/service/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def run(self):
try:
OK = self.upload_batch()
except Exception as ex:
self.log(str(ex))
self.logger.exception(ex)
OK = False
if OK:
pause = polling_interval
Expand Down
2 changes: 1 addition & 1 deletion src/pywws/service/copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def upload_file(self, session, path):
os.makedirs(self.params['directory'])
shutil.copy(path, self.params['directory'])
except Exception as ex:
return False, str(ex)
return False, repr(ex)
return True, 'OK'


Expand Down
2 changes: 1 addition & 1 deletion src/pywws/service/cwop.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def upload_data(self, session, prepared_data={}):
session.sendall(packet)
session.shutdown(socket.SHUT_RDWR)
except Exception as ex:
return False, str(ex)
return False, repr(ex)
return True, 'OK'


Expand Down
2 changes: 1 addition & 1 deletion src/pywws/service/ftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def upload_file(self, session, path):
else:
session.storbinary('STOR %s' % (target), f)
except Exception as ex:
return False, str(ex)
return False, repr(ex)
return True, 'OK'


Expand Down
2 changes: 1 addition & 1 deletion src/pywws/service/mastodon.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def upload_file(self, session, filename):
media_ids.append(rsp['id'])
rsp = session.status_post(status=toot, media_ids=media_ids)
except Exception as ex:
return False, str(ex)
return False, repr(ex)
return True, 'OK'

def register(self):
Expand Down
2 changes: 1 addition & 1 deletion src/pywws/service/metoffice.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def upload_data(self, session, prepared_data={}):
rsp = session.get('http://wow.metoffice.gov.uk/automaticreading',
params=prepared_data, timeout=60)
except Exception as ex:
return False, str(ex)
return False, repr(ex)
if rsp.status_code == 429:
# UK Met Office server uses 429 to signal duplicate data
return True, 'repeated data {:s}'.format(prepared_data['dateutc'])
Expand Down
4 changes: 2 additions & 2 deletions src/pywws/service/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def upload_data(self, session, prepared_data={}):
session.publish(self.params['topic'], json.dumps(prepared_data),
retain=self.params['retain'])
except Exception as ex:
return False, str(ex)
return False, repr(ex)
if self.params['multi_topic']:
# Publish messages, one for each item in prepared_data to
# separate Subtopics.
Expand All @@ -213,7 +213,7 @@ def upload_data(self, session, prepared_data={}):
session.publish(self.params['topic'] + "/" + key, value,
retain=self.params['retain'])
except Exception as ex:
return False, str(ex)
return False, repr(ex)
# Need to make sure the messages have been flushed to the
# server.
session.loop(timeout=0.5)
Expand Down
10 changes: 5 additions & 5 deletions src/pywws/service/openweathermap.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def upload_data(self, session, prepared_data={}):
try:
rsp = session.post(url, json=[prepared_data], timeout=60)
except Exception as ex:
return False, str(ex)
return False, repr(ex)
if rsp.status_code != 204:
return False, 'http status: {:d} {:s}'.format(
rsp.status_code, rsp.text)
Expand All @@ -155,7 +155,7 @@ def register(self):
try:
rsp = session.get(url, timeout=60)
except Exception as ex:
print('exception', str(ex))
print('exception', repr(ex))
return
stations = rsp.json()
if stations:
Expand Down Expand Up @@ -189,7 +189,7 @@ def register(self):
session.delete(
url + '/' + station['id'], timeout=60)
except Exception as ex:
print('exception', str(ex))
print('exception', repr(ex))
return
if station_id:
# update existing station
Expand All @@ -198,7 +198,7 @@ def register(self):
try:
rsp = session.put(url, json=data, timeout=60)
except Exception as ex:
print('exception', str(ex))
print('exception', repr(ex))
return
rsp = rsp.json()
logger.debug('response: ' + repr(rsp))
Expand All @@ -208,7 +208,7 @@ def register(self):
try:
rsp = session.post(url, json=data, timeout=60)
except Exception as ex:
print('exception', str(ex))
print('exception', repr(ex))
return
rsp = rsp.json()
logger.debug('response: ' + repr(rsp))
Expand Down
2 changes: 1 addition & 1 deletion src/pywws/service/pwsweather.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def upload_data(self, session, prepared_data={}):
'http://www.pwsweather.com/pwsupdate/pwsupdate.php',
params=prepared_data, timeout=60)
except Exception as ex:
return False, str(ex)
return False, repr(ex)
if rsp.status_code != 200:
return False, 'http status: {:d}'.format(rsp.status_code)
text = rsp.text.strip()
Expand Down
2 changes: 1 addition & 1 deletion src/pywws/service/sftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def upload_file(self, session, path):
try:
session.put(path, target)
except Exception as ex:
return False, str(ex)
return False, repr(ex)
return True, 'OK'


Expand Down
2 changes: 1 addition & 1 deletion src/pywws/service/temperaturnu.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def upload_data(self, session, prepared_data={}):
rsp = session.get('http://www.temperatur.nu/rapportera.php',
params=prepared_data, timeout=60)
except Exception as ex:
return False, str(ex)
return False, repr(ex)
if rsp.status_code != 200:
return False, 'http status: {:d}'.format(rsp.status_code)
text = rsp.text.strip()
Expand Down
2 changes: 1 addition & 1 deletion src/pywws/service/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def upload_file(self, session, filename):
try:
session.post(tweet, media)
except Exception as ex:
message = str(ex)
message = repr(ex)
return 'is a duplicate' in message, message
return True, 'OK'

Expand Down
2 changes: 1 addition & 1 deletion src/pywws/service/underground.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def upload_data(self, session, prepared_data={}):
try:
rsp = session.get(url, params=prepared_data, timeout=60)
except Exception as ex:
return False, str(ex)
return False, repr(ex)
if rsp.status_code != 200:
return False, 'http status: {:d}'.format(rsp.status_code)
text = rsp.text.strip()
Expand Down
2 changes: 1 addition & 1 deletion src/pywws/service/weathercloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def upload_data(self, session, prepared_data={}):
try:
rsp = session.get(url, params=prepared_data, timeout=60)
except Exception as ex:
return False, str(ex)
return False, repr(ex)
text = rsp.text.strip()
if text in self.errors:
return False, '{} ({})'.format(self.errors[text], text)
Expand Down
2 changes: 1 addition & 1 deletion src/pywws/service/wetterarchivde.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def upload_data(self, session, prepared_data={}):
rsp = session.post('http://interface.wetterarchiv.de/weather/',
data=prepared_data, timeout=60)
except Exception as ex:
return False, str(ex)
return False, repr(ex)
if rsp.status_code != 200:
return False, 'http status: {:d}'.format(rsp.status_code)
rsp = rsp.json()
Expand Down

0 comments on commit 15bd807

Please sign in to comment.