I use the telethon library, everything was fine, exactly until the moment I wanted to create a message dump, when I try to do this, it throws an error that can't pickle _asyncio.Future objects , who can tell _asyncio.Future objects how to deal with it? code:

 client = TelegramClient('telegram', CONST.TG_API_ID, CONST.TG_API_HASH) @client.on(events.NewMessage) async def message_log(event: events.NewMessage.Event): msg = pickle.dumps(event.message) with client.start(): client.run_until_disconnected() 
  • one
    Your code mixes synchronous and asynchronous styles. Thanks to "magic" it works for some methods. If you are just starting with telethon (working with the> = 1.0 version), then use the asynchronous style everywhere (it will be obvious why writing Future to disk just doesn't make sense) - jfs

1 answer 1

Apparently, Message inherits Future . You will have to get the event.message interest from event.message , save them to any structure that supports serialization, and dump it already:

 msg = pickle.dumps({ 'text': event.message.message, 'from': event.message.from_id, }) 
  • Wonderful! But I would like it if I saved an instance of the message class, since there can be not only text, but also a picture and geolocation, and in general a lot of things. - Maxim Sivash
  • And you will have to extract all this before, since the Message cannot be serialized due to its asynchronous nature. - Sergey Gornostaev