From 0eac3065d5409bb5907f2555c157e725485e9e39 Mon Sep 17 00:00:00 2001 From: JC Francois Date: Sun, 8 Sep 2019 19:03:43 +0200 Subject: [PATCH] Added fix for crash when mime_type is NoneType --- twoot.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/twoot.py b/twoot.py index af9d454..eaf6833 100755 --- a/twoot.py +++ b/twoot.py @@ -314,9 +314,15 @@ def main(argv): # Download picture media = requests.get(photo) + # Fix to avoid media_post failing because mime_type is NoneType + # "Can only concatenate str to str" + mime_type = media.headers.get('content-type') + if type(mime_type) is None: + mime_type = "" + # Upload picture to Mastodon instance try: - media_posted = mastodon.media_post(media.content, mime_type=media.headers.get('content-type')) + media_posted = mastodon.media_post(media.content, mime_type) media_ids.append(media_posted['id']) except MastodonAPIError: # Media cannot be uploaded (invalid format, dead link, etc.) pass