codl / mastodon-apod

pictures of space for long-dead elephants
https://botsin.space/@apod
3 stars 0 forks source link

Validation Fails When Posting - Error 422 Unprocessable Entity Char Limit Exceeded #140

Closed Drakynn closed 1 year ago

Drakynn commented 1 year ago

Bot is authenticating properly when first started, but fails to post content with the following error


[2022-12-31 20:21:30] apod: Starting ApodBot apod
[2022-12-31 20:21:30] apod.check_apod: Started
[2022-12-31 20:21:30] apod: Startup complete.
[2023-01-01 01:28:08] apod.check_apod: Exception encountered in @interval function: MastodonAPIError('Mastodon API returned error', 422, 'Unprocessable Entity', 'Validation failed: Text character limit of 500 exceeded')
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/ananas/ananas.py", line 377, in interval_threadproc
    f()
  File "/root/mastodon-apod-main/apod.py", line 221, in check_apod
    self.mastodon.status_post(post_text, media_ids=medias)
  File "/usr/local/lib/python3.11/site-packages/decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/mastodon/Mastodon.py", line 102, in wrapper
    return function(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/mastodon/Mastodon.py", line 1776, in status_post
    return self.__api_request('POST', '/api/v1/statuses', params, headers = headers, use_json = use_json)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/mastodon/Mastodon.py", line 3425, in __api_request
    raise ex_type(
mastodon.Mastodon.MastodonAPIError: ('Mastodon API returned error', 422, 'Unprocessable Entity', 'Validation failed: Text character limit of 500 exceeded')```
codl commented 1 year ago

that's odd, depending on your timezone it would have either been this post or this post, which both fit in 500 characters

Drakynn commented 1 year ago

It seems to be spitting the above error every 6 hours when it activates to check in and post.

This is a fresh Mastodon server with no pre-existing posts on the account.

codl commented 1 year ago

I think I see what's happened, looks like the system that finds the most recent image when posting for the very first time is broken.

I'll be able to fix this sometime next week, until then you can bootstrap it by logging in as the bot and posting a public post with the URL of yesterday's APOD page and the hashtag #APOD. Next time it tries to post it will start from there.

BTW you can force the bot to check for a new page now instead of waiting six hours, if you edit its configuration to set yourself as admin like so:

[apod]
class = ...
client_id = ...
...
admin = codl@chitter.xyz

and then send any message to the bot as that admin account.

Drakynn commented 1 year ago

Manually initializing the first post does solve the problem. Good catch. Thanks.

codl commented 1 year ago

Took me long enough, but the logic for finding the latest page has been changed and this should not happen again. Thanks for bringing this up!