mirror of
https://gitlab.com/jeancf/twoot.git
synced 2024-11-23 20:11:11 +00:00
Handle 422 errors differently
This commit is contained in:
parent
0bee03dd56
commit
9231a78881
34
twoot.py
34
twoot.py
|
@ -1219,22 +1219,24 @@ def main(argv):
|
||||||
toot = mastodon.status_post(tweet['tweet_text'], replied_to_toot, media_ids=media_ids)
|
toot = mastodon.status_post(tweet['tweet_text'], replied_to_toot, media_ids=media_ids)
|
||||||
|
|
||||||
except MastodonAPIError as e:
|
except MastodonAPIError as e:
|
||||||
logging.debug('PROBING DETAILS OF MastodonAPIError')
|
_, _, _, exception_message = e.args
|
||||||
logging.debug(e.args)
|
if 'Text character limit' in exception_message:
|
||||||
logging.debug(e.__notes__)
|
# ERROR (('Mastodon API returned error', 422, 'Unprocessable Entity', 'Validation failed: Text character limit of 500 exceeded'))
|
||||||
# Assuming this is an:
|
logging.error('Tweet text too long: %s characters', str(len(tweet['tweet_text'])))
|
||||||
# ERROR ('Mastodon API returned error', 422, 'Unprocessable Entity', 'Cannot attach files that have not finished processing. Try again in a moment!')
|
shutdown(-1)
|
||||||
logging.warning('Mastodon API Error 422: Cannot attach files that have not finished processing. Waiting 30 seconds and retrying.')
|
elif 'Try again in a moment' in exception_message:
|
||||||
# Wait 30 seconds
|
# ERROR ('Mastodon API returned error', 422, 'Unprocessable Entity', 'Cannot attach files that have not finished processing. Try again in a moment!')
|
||||||
time.sleep(30)
|
logging.warning('Mastodon API Error 422: Cannot attach files that have not finished processing. Waiting 30 seconds and retrying.')
|
||||||
# retry posting
|
# Wait 30 seconds
|
||||||
try:
|
time.sleep(30)
|
||||||
toot = mastodon.status_post(tweet['tweet_text'], media_ids=media_ids)
|
# retry posting
|
||||||
except MastodonError as me:
|
try:
|
||||||
logging.error('posting ' + tweet['tweet_text'] + ' to ' + TOML['config']['mastodon_instance'] + ' Failed')
|
toot = mastodon.status_post(tweet['tweet_text'], media_ids=media_ids)
|
||||||
logging.error(me)
|
except MastodonError as me:
|
||||||
else:
|
logging.error('posting ' + tweet['tweet_text'] + ' to ' + TOML['config']['mastodon_instance'] + ' Failed')
|
||||||
logging.warning("Retry successful")
|
logging.error(me)
|
||||||
|
else:
|
||||||
|
logging.warning("Retry successful")
|
||||||
|
|
||||||
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')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user