From 1b1faf2d590d8fc67bf7a79a337f6277caae418b Mon Sep 17 00:00:00 2001 From: JC Francois Date: Mon, 26 Aug 2019 21:02:19 +0200 Subject: [PATCH] Added tolerance for mastodonAPIError when uploading invalid media --- twoot.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/twoot.py b/twoot.py index 6723fe9..310fa01 100755 --- a/twoot.py +++ b/twoot.py @@ -27,7 +27,7 @@ from bs4 import BeautifulSoup, element import sqlite3 import time import re -from mastodon import Mastodon, MastodonError +from mastodon import Mastodon, MastodonError, MastodonAPIError USER_AGENTS = [ @@ -312,8 +312,11 @@ def main(argv): media = requests.get(photo) # Upload picture to Mastodon instance - media_posted = mastodon.media_post(media.content, mime_type=media.headers.get('content-type')) - media_ids.append(media_posted['id']) + try: + media_posted = mastodon.media_post(media.content, mime_type=media.headers.get('content-type')) + media_ids.append(media_posted['id']) + except MastodonAPIError: # Media cannot be uploaded (invalid format, dead link, etc.) + pass # Post toot try: