mirror of
https://gitlab.com/jeancf/twoot.git
synced 2025-02-21 15:52:08 +00:00
Added tolerance for invalid media links
This commit is contained in:
parent
51f7ca9694
commit
56a89ec4f3
21
twoot.py
21
twoot.py
|
@ -308,19 +308,20 @@ def main(argv):
|
||||||
# Upload photos
|
# Upload photos
|
||||||
media_ids = []
|
media_ids = []
|
||||||
for photo in tweet['photos']:
|
for photo in tweet['photos']:
|
||||||
|
media = False
|
||||||
# Download picture
|
# Download picture
|
||||||
media = requests.get(photo)
|
try:
|
||||||
|
media = requests.get(photo)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
# Upload picture to Mastodon instance
|
# Upload picture to Mastodon instance
|
||||||
try:
|
if media:
|
||||||
media_posted = mastodon.media_post(media.content, mime_type=media.headers['content-type'])
|
try:
|
||||||
media_ids.append(media_posted['id'])
|
media_posted = mastodon.media_post(media.content, mime_type=media.headers['content-type'])
|
||||||
except MastodonAPIError: # Media cannot be uploaded (invalid format, dead link, etc.)
|
media_ids.append(media_posted['id'])
|
||||||
pass
|
except (MastodonAPIError, MastodonIllegalArgumentError, TypeError): # Media cannot be uploaded (invalid format, dead link, etc.)
|
||||||
except MastodonIllegalArgumentError: # Could not determine mime type of content
|
pass
|
||||||
pass
|
|
||||||
except TypeError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Post toot
|
# Post toot
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user