omit bare except.

This commit is contained in:
Thomas L 2018-03-29 01:25:17 +02:00
parent 4981223ee8
commit bfc311b6c9
4 changed files with 10 additions and 13 deletions

View file

@ -21,7 +21,7 @@ class MastodonBot(Bot):
m = Mastodon(*user.get_masto_credentials()) m = Mastodon(*user.get_masto_credentials())
try: try:
notifications = m.notifications() notifications = m.notifications()
except: # mastodon.Mastodon.MastodonAPIError is unfortunately not in __init__.py except Exception:
logger.error("Unknown Mastodon API Error.", exc_info=True) logger.error("Unknown Mastodon API Error.", exc_info=True)
return mentions return mentions
for status in notifications: for status in notifications:

View file

@ -4,7 +4,7 @@ import active_bots
from config import config from config import config
from db import db from db import db
import logging import logging
import sendmail from sendmail import sendmail
import time import time
@ -30,12 +30,9 @@ if __name__ == '__main__':
for bot2 in bots: for bot2 in bots:
bot2.post(user, status) bot2.post(user, status)
time.sleep(60) # twitter rate limit >.< time.sleep(60) # twitter rate limit >.<
except: except Exception:
logger.error('Shutdown', exc_info=True) logger.error('Shutdown.', exc_info=True)
mailer = sendmail.Mailer() try:
try: sendmail(config['web']['contact'], 'Ticketfrei Shutdown')
mailer.send('', config['web']['contact'], except Exception:
'Ticketfrei Crash Report', logger.error('Could not inform admin.', exc_info=True)
attachment=config['logging']['logpath'])
except:
logger.error('Mail sending failed', exc_info=True)

View file

@ -150,7 +150,7 @@ def login_mastodon(user):
return dict( return dict(
info='Thanks for supporting decentralized social networks!' info='Thanks for supporting decentralized social networks!'
) )
except: except Exception:
logger.error('Login to Mastodon failed.', exc_info=True) logger.error('Login to Mastodon failed.', exc_info=True)
return dict(error='Login to Mastodon failed.') return dict(error='Login to Mastodon failed.')

View file

@ -64,7 +64,7 @@ class Mailer(object):
return "Sent mail to " + recipient + ": " + subject return "Sent mail to " + recipient + ": " + subject
def sendmail(to, subject, body): def sendmail(to, subject, body=''):
msg = MIMEMultipart() msg = MIMEMultipart()
msg['From'] = '%s@%s' % (getuser(), getfqdn()) msg['From'] = '%s@%s' % (getuser(), getfqdn())
msg['To'] = to msg['To'] = to