Telethon: No module named 'telethon.tl.all_tlobjects'

Created on 16 Jan 2017  ·  17Comments  ·  Source: LonamiWebs/Telethon

I see you put 'all_tlobjects' in .gitignore but other file ares depending on it.

Most helpful comment

@XyLoNaMiyX By doing that I'm receiving below error

Traceback (most recent call last):
  File "telethon_generator/tl_generator.py", line 5, in <module>
    from .parser import SourceBuilder, TLParser
SystemError: Parent module '' not loaded, cannot perform relative import

I'm using python 3.5.2

All 17 comments

Step 4. on the README.rst:

Run the code generator: python3 telethon_generator/tl_generator.py

@XyLoNaMiyX By doing that I'm receiving below error

Traceback (most recent call last):
  File "telethon_generator/tl_generator.py", line 5, in <module>
    from .parser import SourceBuilder, TLParser
SystemError: Parent module '' not loaded, cannot perform relative import

I'm using python 3.5.2

Remove the . from from .parser import SourceBuilder, TLParser:

from parser import SourceBuilder, TLParser
Generating TLObjects...
Traceback (most recent call last):
  File "telethon_generator/tl_generator.py", line 475, in <module>
    TLGenerator.generate_tlobjects('scheme.tl')
  File "telethon_generator/tl_generator.py", line 39, in generate_tlobjects
    tlobjects = tuple(TLParser.parse_file(scheme_file))
  File "/home/simon/Nightybuild/Telethon/telethon_generator/parser/tl_parser.py", line 13, in parse_file
    with open(file_path, encoding='utf-8') as file:
FileNotFoundError: [Errno 2] No such file or directory: 'scheme.tl'

You need to be on the telethon_generator directory, not outside. README.rst is a bit confusing but it's not really a big deal… I don't know why python3 telethon_generator/tl_generator.py doesn't consider the current directory to be the parent module.

If I had:

from parser import SourceBuilder, TLParser

Then my IDE would error saying it can't find the parser module and I hate errors, so I leave the . :P

Okay now it's working.!

@XyLoNaMiyX I wanted to receive continuously for the message from one channel. How do I achieve that using this Telethon ? Please hint me

Well Telethon already has an updates thread, new messages should arrive there automatically. Please take a look at the source code to see how it works for you to get an idea.

Hi @XyLoNaMiyX Please help me with this...

My goal is to write the functions to get the list of channels from the user.

channel_request = tl.functions.channels.get_channels.GetChannelsRequest
client.sender.receive(channel_request)

But above code throws *** AttributeError: type object 'MTProtoRequest' has no attribute 'confirm_received'

GetChannelsRequest takes a id: Telegram type: «InputChannel». Must be a list. (a list of InputChannel). This is probably not what you intend to do. I think you're looking to retrieve the dialogs (dialogs = "open conversations", either with users, groups or channels). And the TelegramClient provides .get_dialogs.

Also, you're not even creating an instance of GetChannelsRequest. You're just assigning the whole type to another variable. I suggest you to read Dive Into Python 3 to get started.

I'm testing receive anything with

while True:
    recv = client.transport.receive()
    time.sleep(4)

Received bytes can't able to decode

(Pdb) recv[1].decode('utf-8')
*** UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd1 in position 0: invalid continuation byte

I'm testing receive anything

You should not be using the transport directly.

Documentation is not quite clear. I'm still struggling to work with Telethon. My goal is very clear. All I want is retrive the list of dialogs thanks to get_dialogs methods. And find the channel and retrive that channel message in real time. Please can you help me with this ?

  1. Create a TelegramClient instance.
  2. Call .get_dialogs(). This will return a (dialogs, entities) tuple.
  3. The channels are under entities. Just iterate the list and check with isinstance(), it will be of type Channel.

Let me be honest, I'm not going to make your program. Once again this is something you can easily see if you look into Telethon's code (just like I did right now) but I cannot be your personal assistant on every step you give.

Thanks for the clarification. This is entirely new to me so that's the buzz. I like you to take one last final glance with this... Now I modify the code something to this...

# Get all the dialogs of the user. Note that get_dialogs return tuble
dialogs, entities = client.get_dialogs()

# Processing entities to check Channel or not.
for entity in entities:
    # Check the instance
    if isinstance(entity, Channel):
        client.add_update_handler(entity)
        request = entity

result = client.add_update_handler(request)
print(result)

I have two doubts here. One is it throwing error some point...

Traceback (most recent call last):
  File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.5/threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
  File "/home/simon/Nightybuild/Telethon/telethon/network/mtproto_sender.py", line 361, in updates_thread_method
    reader)
  File "/home/simon/Nightybuild/Telethon/telethon/network/mtproto_sender.py", line 222, in process_msg
    return self.handle_update(msg_id, sequence, reader)
  File "/home/simon/Nightybuild/Telethon/telethon/network/mtproto_sender.py", line 235, in handle_update
    handler(tlobject)
TypeError: 'Channel' object is not callable

And another one. Is that my code is right for receiving messages for that particular client ?

Have you read the code as I adviced you?:

"""Adds an update handler (a function which takes a TLObject,
an update, as its parameter) and listens for updates"""

You need to pass a function with an argument. Not the type. The code you showed successfully retrieves the channels but you can't invoke a channel. Furthermore add_update_handler returns nothing. The function you pass will be invoked on upates, i.e., a message arrives.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mircoianese picture mircoianese  ·  3Comments

wdsjxh picture wdsjxh  ·  3Comments

Lerbytech picture Lerbytech  ·  5Comments

amir3code picture amir3code  ·  6Comments

denilen picture denilen  ·  3Comments