From 806b57f763a2c4e7a088dd0265367de97bcd0c52 Mon Sep 17 00:00:00 2001 From: JC Francois Date: Sat, 7 Sep 2019 13:08:17 +0200 Subject: [PATCH] Added tolerance for MastodonIllegalArgumentError when visiting linked page to extract picture --- twoot.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/twoot.py b/twoot.py index fc349ee..af9d454 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, MastodonAPIError +from mastodon import Mastodon, MastodonError, MastodonAPIError, MastodonIllegalArgumentError USER_AGENTS = [ @@ -208,10 +208,10 @@ def main(argv): for p in photo_conts: photos.append(p['data-image-url']) - # Mention presence in videos in tweet + # Mention presence of videos in tweet videos = amoc.find_all('div', class_='AdaptiveMedia-videoContainer') if len(videos) != 0: - tweet_text += '\n\n[Embedded video in original tweet]' + tweet_text += '\n\n[Video embedded in original tweet]' # If no media was specifically added in the tweet, try to get the first picture # with "twitter:image" meta tag in first linked page in tweet text @@ -320,6 +320,8 @@ def main(argv): media_ids.append(media_posted['id']) except MastodonAPIError: # Media cannot be uploaded (invalid format, dead link, etc.) pass + except MastodonIllegalArgumentError: # Could not determine mime type of content + pass # Post toot try: