From 1acd03987121519f373fa4a679b34855e67e7169 Mon Sep 17 00:00:00 2001 From: cquest Date: Sun, 2 Jul 2023 10:56:24 +0200 Subject: [PATCH] handle non retrievable pictures (403) --- tootbot.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tootbot.py b/tootbot.py index cd4f4dc..e59bafa 100755 --- a/tootbot.py +++ b/tootbot.py @@ -167,10 +167,11 @@ if source[:4] == 'http': if 'links' in t: for l in t.links: if l.type in ('image/gif', 'image/jpg', 'image/png', 'image/webp'): - media = requests.get(l.url) - media_posted = mastodon_api.media_post( - media.content, mime_type=media.headers.get('content-type')) - toot_media.append(media_posted['id']) + media = requests.get(l.url, headers = {'User-agent': 'Mozilla/5.0'}) + if media.status_code == 200: + media_posted = mastodon_api.media_post( + media.content, mime_type=media.headers.get('content-type')) + toot_media.append(media_posted['id']) # replace short links by original URL m = re.search(r"http[^ \xa0]*", c)