Search code examples
pythontelethon

Telethon error when import InputPeerChannel


I just started learning python. Now I'm doing a bot for Telegram. To work with the Core API, I use the Telethon library for Python 3. The error occurs in the line:

from telethon.utils import InputPeerChannel

Error text:

Traceback (most recent call last):
  File "F:\Work\Projects\Python\Bots\NewsBot\main.py", line 5, in <module>
    from telethon.utils import InputPeerChannel
ImportError: cannot import name 'InputPeerChannel' from 'telethon.utils' (F:\Work\Projects\Python\Bots\NewsBot\venv\lib\site-packages\telethon\utils.py)
  • Version Telethon 1.24.0
  • Python 3.9
  • IDE PyCharm

Solution

  • An ImportError in python indicates that the name (InputPeerChannel in this case) isn't in the module (telethon.utils in this case) or that the module can't be found.

    In your case happens the first, the module telethon.utils exists but it not contains the name InputPeerChannel. This name can be found in the module tlethon.tl.types so you can import it from there.

    >>> from telethon.tl.types import InputPeerChannel