mirror of
https://gitlab.com/jeancf/twoot.git
synced 2025-02-17 13:58:11 +00:00
Added tolerance for mastodonAPIError when uploading invalid media
This commit is contained in:
parent
5b23c66b6b
commit
1b1faf2d59
9
twoot.py
9
twoot.py
|
@ -27,7 +27,7 @@ from bs4 import BeautifulSoup, element
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import time
|
import time
|
||||||
import re
|
import re
|
||||||
from mastodon import Mastodon, MastodonError
|
from mastodon import Mastodon, MastodonError, MastodonAPIError
|
||||||
|
|
||||||
|
|
||||||
USER_AGENTS = [
|
USER_AGENTS = [
|
||||||
|
@ -312,8 +312,11 @@ def main(argv):
|
||||||
media = requests.get(photo)
|
media = requests.get(photo)
|
||||||
|
|
||||||
# Upload picture to Mastodon instance
|
# Upload picture to Mastodon instance
|
||||||
media_posted = mastodon.media_post(media.content, mime_type=media.headers.get('content-type'))
|
try:
|
||||||
media_ids.append(media_posted['id'])
|
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
|
# Post toot
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user