Closed danil-lashin closed 7 years ago
I have the same error. I don't know when this error occurred but I remove session file and retry. It's work.
Telethon probably crashed when trying to receive a request before, I assume. So Telegram just keeps sending the rest of that old request which you couldn't fully receive. And since Telethon doesn't know it was receiving a request before, it cannot carry on, and attempts to read a new request (starting with its constructor ID) which, obviously, doesn't match.
A possible workaround would maybe read until there is no more data left. Not the best option though.
I get the error after rerun this code. At first run, the code worked properly but at second run error happened.
from telethon import TelegramClient
from telethon.tl.functions.messages import GetMessagesViewsRequest
from telethon.utils import InputPeerChannel
client = TelegramClient('@Sess', api_id, api_hash)
client.connect()
username = 'VahidOnline'
channel_info = client.invoke(ResolveUsernameRequest(username))
cid = channel_info.peer.channel_id
ah = channel_info.chats[0].access_hash
client.invoke(GetMessagesViewsRequest(InputPeerChannel(cid, ah), [23901], False))
@gtavasoli I tried your code and I can confirm that such a strange behaviour occurs. What happens, though, is that after invoking the InitConnectionRequest
, 0x1cb5c415
is received. This corresponds to a vector, so I would guess that Telegram is resending the result. Why? I don't know.
Alright indeed, I get the last result, which is a vector of integers, and then I receive an ack
for InitConnectionRequest
. There's one problem, though. Currently there's no way of telling whether the result I'm reading for a request is of the correct type. And even if there was, there's no way of telling the type of objects to be read for the vector (it's just a "vector", I have to guess the type). So even if I added support to read vectors as a generic object, it would fail, because I wouldn't know the size of the objects about to be read. Ideas?
Started getting this error when trying to get history of several channels. Other are working fine
Hi! I also got this error.
Traceback (most recent call last): File "F:\Python35-32\telegram_API\test - copy.py", line 21, in <module> client.connect() File "C:\Python\Python35-32\lib\site-packages\telethon\telegram_client.py", line 118, in connect layer=layer, query=query)) File "C:\Python\Python35-32\lib\site-packages\telethon\telegram_client.py", line 175, in invoke self.sender.receive(request, timeout) File "C:\Python\Python35-32\lib\site-packages\telethon\network\mtproto_sender.py", line 139, in receive request) File "C:\Python\Python35-32\lib\site-packages\telethon\network\mtproto_sender.py", line 222, in process_msg return self.handle_container(msg_id, sequence, reader, request) File "C:\Python\Python35-32\lib\site-packages\telethon\network\mtproto_sender.py", line 285, in handle_container if not self.process_msg(inner_msg_id, sequence, reader, request): File "C:\Python\Python35-32\lib\site-packages\telethon\network\mtproto_sender.py", line 217, in process_msg return self.handle_rpc_result(msg_id, sequence, reader, request) File "C:\Python\Python35-32\lib\site-packages\telethon\network\mtproto_sender.py", line 363, in handle_rpc_result request.on_response(reader) File "C:\Python\Python35-32\lib\site-packages\telethon\tl\functions\invoke_with_layer.py", line 34, in on_response self.result = reader.tgread_object() File "C:\Python\Python35-32\lib\site-packages\telethon\utils\binary_reader.py", line 123, in tgread_object raise TypeNotFoundError(constructor_id) telethon.errors.TypeNotFoundError: (TypeNotFoundError(...), 'Could not find a matching Constructor ID for the TLObject that was supposed to be read with ID 0x1cb5c415. Most likely, a TLObject was trying to be read when it should not be read.')
2 or 3 requests went fine, then this error, and I can not Create the client and connect.
Starting with this code, an error is generated.
# (2) Create the client and connect client = TelegramClient('username', api_id, api_hash) client.connect()
It starts working fine again if I create a new .session file and then again an error after several requests.
I worked with ImportContactsRequest, DeleteContactRequest, GetUsersRequest
Solved this error by doing this:
def tgread_object(self):
"""Reads a Telegram object"""
constructor_id = self.read_int(signed=False)
clazz = tlobjects.get(constructor_id, None)
if clazz is None:
value = constructor_id
if value == 0x997275b5: # boolTrue
return True
elif value == 0xbc799737: # boolFalse
return False
# **--> HERE: if error then try to use next int as constructor_id <--**
return self.tgread_object()
Solved this error by doing this: …
For what requests did it solve the error? Does it actually read the expected object?
@Lonami, for all my requests. Especially for "get message history" and "get full channel". And yep, it works as expected.
It… would be a strange fix to just ignore an object ID, usually, its length comes after it, and then, n
items. But if Telegram is just sending it yet it's safe to ignore. Not sure if we should keep that "fix", it seems awkward at first.
And yep, it works as expected.
It doesn't for me, I tried with the example posted above, and then, tried to read a tgobject
. It failed, since the integer returned was 1 (the length of the vector).
Tested, #89 works. Nice job, @cher-nov!
Tested, #89 works. Nice job, @cher-nov!
I have error seem the same but I cannot fix it with #89. I am using Telethon to forward chat from group A to group B. Anything works well if text chat only, the error come up when user send gif , image and sticker.
Traceback (most recent call last): File "C:\telegram-recorder-master\main.py", line 117, in <module> client.idle() File "C:\Program Files\Python36\lib\site-packages\telethon\telegram_bare_client.py", line 696, in idle self._sender.receive(update_state=self.updates) File "C:\Program Files\Python36\lib\site-packages\telethon\network\mtproto_sender.py", line 180, in receive self._process_msg(remote_msg_id, remote_seq, reader, update_state) File "C:\Program Files\Python36\lib\site-packages\telethon\network\mtproto_sender.py", line 234, in _process_msg return self._handle_container(msg_id, sequence, reader, state) File "C:\Program Files\Python36\lib\site-packages\telethon\network\mtproto_sender.py", line 392, in _handle_container if not self._process_msg(inner_msg_id, sequence, reader, state): File "C:\Program Files\Python36\lib\site-packages\telethon\network\mtproto_sender.py", line 247, in _process_msg obj = reader.tgread_object() File "C:\Program Files\Python36\lib\site-packages\telethon\extensions\binary_reader.py", line 143, in tgread_object return clazz.from_reader(self) File "C:\Program Files\Python36\lib\site-packages\telethon\tl\types\__init__.py", line 20542, in from_reader _x = reader.tgread_object() File "C:\Program Files\Python36\lib\site-packages\telethon\extensions\binary_reader.py", line 141, in tgread_object raise TypeNotFoundError(constructor_id) telethon.errors.common.TypeNotFoundError: Could not find a matching Constructor ID for the TLObject that was supposed to be read with ID 0x450b7115. Most likely, a TLObject was trying to be read when it should not be read..
I don't need forward image or gif so can you help me to ignore, skip the gif /image chat.
@pspvhp you are using a very old version (I can tell from your client.idle()
which doesn't exist in newer versions). For anyone having this issue, the only solution is to update (or to manually mantain that very old version yourself with a recent layer).
Hi!
I'm having strange error when trying to invoke GetHistoryRequest, can you help me? This error started to occur recently, have no problem with it yesterday.