Telethon icon indicating copy to clipboard operation
Telethon copied to clipboard

conservation.get_response() TypeError: '<' not supported between instances of 'float' and 'NoneType'

Open Sonys9 opened this issue 8 months ago • 8 comments

Code that causes the issue

from telethon import TelegramClient

async def create_bot(client : TelegramClient, username):

    conservation = client.conversation("@BotFather", exclusive=False)
    msg = await conservation.send_message('/newbot')
    response = await conservation.get_response()

Expected behavior

Get response from botfather

Actual behavior

Got error

Traceback

  File "c:\Скрипты\LightLite\init_userbot\init.py", line 16, in initialize
    result = await create_bot(client, bot_username)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Скрипты\LightLite\init_userbot\load_bot.py", line 37, in create_bot
    response = await conservation.get_response(timeout=5)
                     ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
  File "C:\Users\Admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\telethon\tl\custom\conversation.py", line 157, in get_response
    return self._get_message(
           ~~~~~~~~~~~~~~~~~^
        message, self._response_indices, self._pending_responses, timeout,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        lambda x, y: True
        ^^^^^^^^^^^^^^^^^
    )
    ^
  File "C:\Users\Admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\telethon\tl\custom\conversation.py", line 230, in _get_message
    return self._get_result(future, start_time, timeout, pending, target_id)
           ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\telethon\tl\custom\conversation.py", line 22, in wrapper
    return f(self, *args, **kwargs)
  File "C:\Users\Admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\telethon\tl\custom\conversation.py", line 439, in _get_result
    due = min(due, start_time + timeout)
TypeError: '<' not supported between instances of 'float' and 'NoneType'

Telethon version

1.39.0

Python version

3.13.3

Operating system (including distribution name and version)

Windows 11 Pro 22H2

Other details

I tried to add "timeout=5", but didnt helped

Checklist

  • [x] The error is in the library's code, and not in my own.
  • [x] I have searched for this issue before posting it and there isn't an open duplicate.
  • [x] I ran pip install -U https://github.com/LonamiWebs/Telethon/archive/v1.zip and triggered the bug in the latest version.

Sonys9 avatar Apr 17 '25 20:04 Sonys9

why no answer :(

Sonys9 avatar Apr 19 '25 06:04 Sonys9

I have no intention to maintain conversation myself (which is why v2 removes it).

Lonami avatar Apr 19 '25 06:04 Lonami

i gotchu i will try to recode it myself because conservation is nice

Sonys9 avatar Apr 19 '25 07:04 Sonys9

Thanks, and feel free to send a pull request if you find a fix.

Lonami avatar Apr 19 '25 11:04 Lonami

i see due is None, checking why...

Sonys9 avatar Apr 19 '25 15:04 Sonys9

I got it

at start, self._total_due = None

in function aenter if self._total_timeout: self._total_due = time.time() + self._total_timeout else: self._total_due = float('inf') but this function isnt calling

Sonys9 avatar Apr 19 '25 15:04 Sonys9

for some reason, after fixing, its gives TimeoutError, need to check why

Sonys9 avatar Apr 19 '25 15:04 Sonys9

its hard for me, so, i cant fix it :( (and im lazy)

but what i found:

  1. due in _get_result may be None, so, i changed some code to
if timeout is None:
            timeout = self._timeout

        if timeout:
            due = time.time() + timeout
        else:
            due = float('inf')

        if timeout is not None:
            print(due, start_time, timeout)
            due = min(due, start_time + timeout)
  1. I think, its not reading new messages, because incoming list is empty.

Sonys9 avatar Apr 19 '25 16:04 Sonys9