mirror of
https://gitlab.com/jeancf/twoot.git
synced 2025-05-28 19:46:25 +00:00
Proper implementation of mitigation for API Error 422
This commit is contained in:
parent
36248dbce1
commit
38e505ad6e
16
twoot.py
16
twoot.py
@ -952,9 +952,6 @@ def main(argv):
|
|||||||
logging.debug("Uploading video to Mastodon")
|
logging.debug("Uploading video to Mastodon")
|
||||||
media_posted = mastodon.media_post(tweet['video'])
|
media_posted = mastodon.media_post(tweet['video'])
|
||||||
media_ids.append(media_posted['id'])
|
media_ids.append(media_posted['id'])
|
||||||
# Possible mitigation for
|
|
||||||
# ERROR ('Mastodon API returned error', 422, 'Unprocessable Entity', 'Cannot attach files that have not finished processing. Try again in a moment!')
|
|
||||||
time.sleep(5)
|
|
||||||
except (MastodonAPIError, MastodonIllegalArgumentError,
|
except (MastodonAPIError, MastodonIllegalArgumentError,
|
||||||
TypeError): # Media cannot be uploaded (invalid format, dead link, etc.)
|
TypeError): # Media cannot be uploaded (invalid format, dead link, etc.)
|
||||||
logging.debug("Uploading video failed")
|
logging.debug("Uploading video failed")
|
||||||
@ -994,6 +991,19 @@ def main(argv):
|
|||||||
else:
|
else:
|
||||||
toot = mastodon.status_post(tweet['tweet_text'], media_ids=media_ids)
|
toot = mastodon.status_post(tweet['tweet_text'], media_ids=media_ids)
|
||||||
|
|
||||||
|
except MastodonAPIError:
|
||||||
|
# Assuming this is an:
|
||||||
|
# ERROR ('Mastodon API returned error', 422, 'Unprocessable Entity', 'Cannot attach files that have not finished processing. Try again in a moment!')
|
||||||
|
logging.warning('Mastodon API Error 422: Cannot attach files that have not finished processing. Waiting 15 seconds and retrying.')
|
||||||
|
# Wait 10 seconds
|
||||||
|
time.sleep(15)
|
||||||
|
# retry posting
|
||||||
|
try:
|
||||||
|
toot = mastodon.status_post(tweet['tweet_text'], media_ids=media_ids)
|
||||||
|
except MastodonError as me:
|
||||||
|
logging.error('posting ' + tweet['tweet_text'] + ' to ' + TOML['config']['mastodon_instance'] + ' Failed')
|
||||||
|
logging.error(me)
|
||||||
|
|
||||||
except MastodonError as me:
|
except MastodonError as me:
|
||||||
logging.error('posting ' + tweet['tweet_text'] + ' to ' + TOML['config']['mastodon_instance'] + ' Failed')
|
logging.error('posting ' + tweet['tweet_text'] + ' to ' + TOML['config']['mastodon_instance'] + ' Failed')
|
||||||
logging.error(me)
|
logging.error(me)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user