Telethon
Telethon copied to clipboard
TypeError: Cannot cast NoneType to any kind of Peer with update from peers with 64-bit IDs
When a user with 64-bit ID sends a message to Bot (updates for userbot work as expected), there is no peer in incoming update. When "old" user write to bot everything works as expected.
At the start I thought that it's a Telegram server side issue, but their own library works as expected with this kind of updates. So maybe there is error with parsing raw packets from Telegram server?
You could test it by registering new account with one of official Telegram apps and then send /start to bot from that account
UPD: I've also found out that bot receiving update with empty users field in this situation
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 a duplicate.
- [x] I ran
pip install -U https://github.com/LonamiWebs/Telethon/archive/master.zipand triggered the bug in the latest version.
Code that causes the issue
import asyncio
import telethon
API_ID = 0
API_HASH = ""
BOT_TOKEN = ""
client = telethon.TelegramClient(
'bot',
api_id=API_ID,
api_hash=API_HASH,
)
@client.on(telethon.events.NewMessage(pattern='/start'))
async def start_handler(event):
await event.reply("Hello from Telethon!")
async def main():
await client.start(bot_token=BOT_TOKEN)
# Idle...
while True:
await asyncio.sleep(1)
if __name__ == '__main__':
client.loop.run_until_complete(main())
Traceback
Traceback (most recent call last):
File "/Users/pylakey/Workspace/Python/test_polygon/.venv/lib/python3.9/site-packages/telethon/client/updates.py", line 467, in _dispatch_update
await callback(event)
File "/Users/pylakey/Workspace/Python/test_polygon/telethon_test.py", line 24, in start_handler
await event.reply("Hello from Telethon!")
File "/Users/pylakey/Workspace/Python/test_polygon/.venv/lib/python3.9/site-packages/telethon/tl/custom/message.py", line 757, in reply
return await self._client.send_message(
File "/Users/pylakey/Workspace/Python/test_polygon/.venv/lib/python3.9/site-packages/telethon/client/messages.py", line 810, in send_message
entity = await self.get_input_entity(entity)
File "/Users/pylakey/Workspace/Python/test_polygon/.venv/lib/python3.9/site-packages/telethon/client/users.py", line 443, in get_input_entity
peer = utils.get_peer(peer)
File "/Users/pylakey/Workspace/Python/test_polygon/.venv/lib/python3.9/site-packages/telethon/utils.py", line 997, in get_peer
_raise_cast_fail(peer, 'Peer')
File "/Users/pylakey/Workspace/Python/test_polygon/.venv/lib/python3.9/site-packages/telethon/utils.py", line 138, in _raise_cast_fail
raise TypeError('Cannot cast {} to any kind of {}.'.format(
TypeError: Cannot cast NoneType to any kind of Peer.
@Lonami why this is closed? This bug is not solved.
Can you confirm it doesn't work in the latest released version? This is kind of a very big bug so I'm surprised it's only being complained about now.
yes, you may test it with this. @Lonami
from telethon.tl.types import ChannelParticipantCreator, ChannelParticipantAdmin
from telethon.tl.functions.channels import GetParticipantRequest
#..
@client.on(events.NewMessage)
async def handler(event):
participant = await client(GetParticipantRequest(channel=event.original_update.message.to_id.channel_id, participant=event.original_update.message.from_id))
isadmin = (type(participant.participant) == ChannelParticipantAdmin)
iscreator = (type(participant.participant) == ChannelParticipantCreator)
print(isadmin, iscreator)
Closing since this should be working fine in the v1.25 available from PyPi.
nop, not working..
Please make sure you're up to date and provide a code sample that triggers the issue. As I said before this is a big issue so I'd be surprised if it's only being noticed now.