Skip to content

StreamListener spammed with invalid events #434

@ASTRELION

Description

@ASTRELION

My project runs a subclass of StreamListener in a thread that listens for on_notification and on_conversation. It has been working fine for a couple years, but just recently I've been noticing spam for the following error (truncated to the relevant info):

  File "/home/astrelion/Projects/dungeons-bot/.venv/lib/python3.13/site-packages/mastodon/versions.py", line 50, in wrapper
    return function(self, *args, **kwargs)
  File "/home/astrelion/Projects/dungeons-bot/.venv/lib/python3.13/site-packages/mastodon/streaming_endpoints.py", line 20, in stream_user
    return self.__stream('/api/v1/streaming/user', listener, run_async=run_async, timeout=timeout, reconnect_async=reconnect_async, reconnect_async_wait_sec=reconnect_async_wait_sec)
           ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/astrelion/Projects/dungeons-bot/.venv/lib/python3.13/site-packages/mastodon/internals.py", line 523, in __stream
    listener.handle_stream(r)
    ~~~~~~~~~~~~~~~~~~~~~~^^^
  File "/home/astrelion/Projects/dungeons-bot/.venv/lib/python3.13/site-packages/mastodon/streaming.py", line 148, in handle_stream
    self._dispatch(event)
    ~~~~~~~~~~~~~~^^^^^^^
  File "/home/astrelion/Projects/dungeons-bot/.venv/lib/python3.13/site-packages/mastodon/streaming.py", line 203, in _dispatch
    raise exception from err
mastodon.errors.MastodonMalformedEventError: ('Missing field', 'event', {})

This is the line where the error occurs: https://github.com/halcy/Mastodon.py/blob/master/mastodon/streaming.py#L189

I did a little bit of debugging and it seems that I'm getting periodic :thump events that can't be parsed by this event handler.

Is there something I'm doing wrong that causes getting those malformed events, or is it an issue with the library?

Mastodon.py version: tested on 2.1.4 and 1.8
Python: 3.13.11

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions