From b09c20e910c34a5dae192b833ec467eb076edcef Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Sun, 17 Jan 2016 12:04:34 -0600 Subject: [PATCH] twitter: wrap exceptions in str() before format() this might also do something about #1, considering i'm also just doing blanket except Exception:s now. fingers crossed --- dr_botzo/twitter/ircplugin.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/dr_botzo/twitter/ircplugin.py b/dr_botzo/twitter/ircplugin.py index 865bad4..34af317 100644 --- a/dr_botzo/twitter/ircplugin.py +++ b/dr_botzo/twitter/ircplugin.py @@ -95,8 +95,10 @@ class Twitter(Plugin): try: tweet = self.twit.show_status(id=status) return self._return_tweet_or_retweet_text(event, tweet=tweet, print_source=print_source, print_id=print_id) - except twython.exceptions.TwythonError as e: - return self.bot.reply(event, "Couldn't obtain status: {0:s}".format(e)) + except Exception as e: + log.error("couldn't obtain status") + log.exception(e) + return self.bot.reply(event, "Couldn't obtain status: {0:s}".format(str(e))) def handle_getuserstatus(self, connection, event, match): """Get a status for a user. Allows for getting one other than the most recent.""" @@ -130,12 +132,10 @@ class Twitter(Plugin): tweet = tweets[-1*index] return self._return_tweet_or_retweet_text(event, tweet=tweet, print_source=print_source, print_id=print_id) - except requests.exceptions.SSLError as ssle: - return self.bot.reply(event, "Couldn't obtain status: {0:s}, you can maybe try again".format(ssle)) - except twython.exceptions.TwythonError as e: - return self.bot.reply(event, "Couldn't obtain status: {0:s}".format(e)) - except ValueError as e: - return self.bot.reply(event, "Couldn't obtain status: {0:s}".format(e)) + except Exception as e: + log.error("couldn't obtain status") + log.exception(e) + return self.bot.reply(event, "Couldn't obtain status: {0:s}".format(str(e))) def handle_tweet(self, connection, event, match): """Tweet. Needs authentication.""" @@ -151,8 +151,10 @@ class Twitter(Plugin): return self.bot.reply(event, "'{0:s}' tweeted.".format(tweet)) else: return self.bot.reply(event, "Unknown error sending tweet(s).") - except twython.exceptions.TwythonError as e: - return self.bot.reply(event, "Couldn't tweet: {0:s}".format(e)) + except Exception as e: + log.error("couldn't tweet") + log.exception(e) + return self.bot.reply(event, "Couldn't tweet: {0:s}".format(str(e))) def handle_replyto(self, connection, event, match): """Reply to a tweet, in the twitter in_reply_to_status_id sense. Needs authentication.""" @@ -174,8 +176,10 @@ class Twitter(Plugin): return self.bot.reply(event, "'{0:s}' tweeted.".format(tweet)) else: return self.bot.reply(event, "Unknown error sending tweet.") - except twython.exceptions.TwythonError as e: - return self.bot.reply(event, "Couldn't tweet: {0:s}".format(e)) + except Exception as e: + log.error("couldn't tweet") + log.exception(e) + return self.bot.reply(event, "Couldn't tweet: {0:s}".format(str(e))) def handle_gettoken(self, connection, event, match): """Get an oauth token, so that the user may authenticate the bot."""