From 076b41e8537813776fe874186960868676dac832 Mon Sep 17 00:00:00 2001 From: Matt Molyneaux Date: Sat, 24 Nov 2018 23:08:45 +0000 Subject: [PATCH] Catch exceptions from HTTP request We don't need to stop the entire process just because we encountered a temporary error. --- reply.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/reply.py b/reply.py index f4845de..df2795f 100755 --- a/reply.py +++ b/reply.py @@ -4,7 +4,7 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. import mastodon -import os, random, re, json +import os, random, re, json, traceback import create from bs4 import BeautifulSoup @@ -49,8 +49,12 @@ class ReplyListener(mastodon.StreamListener): visibility = notification['status']['visibility'] if visibility == "public": visibility = "unlisted" - client.status_post(toot, post_id, visibility=visibility) - print("replied with " + toot) + try: + client.status_post(toot, post_id, visibility=visibility) + except Exception: + traceback.print_exc() + else: + print("replied with " + toot) rl = ReplyListener() client.stream_user(rl)