From bfc311b6c9f7e22d4369ddb8530c0b1d4681ed21 Mon Sep 17 00:00:00 2001 From: Thomas L Date: Thu, 29 Mar 2018 01:25:17 +0200 Subject: [PATCH] omit bare except. --- active_bots/mastodonbot.py | 2 +- backend.py | 17 +++++++---------- frontend.py | 2 +- sendmail.py | 2 +- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/active_bots/mastodonbot.py b/active_bots/mastodonbot.py index c0e0240..1a313dc 100755 --- a/active_bots/mastodonbot.py +++ b/active_bots/mastodonbot.py @@ -21,7 +21,7 @@ class MastodonBot(Bot): m = Mastodon(*user.get_masto_credentials()) try: notifications = m.notifications() - except: # mastodon.Mastodon.MastodonAPIError is unfortunately not in __init__.py + except Exception: logger.error("Unknown Mastodon API Error.", exc_info=True) return mentions for status in notifications: diff --git a/backend.py b/backend.py index 601e19a..040aac4 100755 --- a/backend.py +++ b/backend.py @@ -4,7 +4,7 @@ import active_bots from config import config from db import db import logging -import sendmail +from sendmail import sendmail import time @@ -30,12 +30,9 @@ if __name__ == '__main__': for bot2 in bots: bot2.post(user, status) time.sleep(60) # twitter rate limit >.< - except: - logger.error('Shutdown', exc_info=True) - mailer = sendmail.Mailer() - try: - mailer.send('', config['web']['contact'], - 'Ticketfrei Crash Report', - attachment=config['logging']['logpath']) - except: - logger.error('Mail sending failed', exc_info=True) + except Exception: + logger.error('Shutdown.', exc_info=True) + try: + sendmail(config['web']['contact'], 'Ticketfrei Shutdown') + except Exception: + logger.error('Could not inform admin.', exc_info=True) diff --git a/frontend.py b/frontend.py index c0b3552..adef914 100755 --- a/frontend.py +++ b/frontend.py @@ -150,7 +150,7 @@ def login_mastodon(user): return dict( info='Thanks for supporting decentralized social networks!' ) - except: + except Exception: logger.error('Login to Mastodon failed.', exc_info=True) return dict(error='Login to Mastodon failed.') diff --git a/sendmail.py b/sendmail.py index f2e754c..3f23452 100755 --- a/sendmail.py +++ b/sendmail.py @@ -64,7 +64,7 @@ class Mailer(object): return "Sent mail to " + recipient + ": " + subject -def sendmail(to, subject, body): +def sendmail(to, subject, body=''): msg = MIMEMultipart() msg['From'] = '%s@%s' % (getuser(), getfqdn()) msg['To'] = to