I am sure the error is coming from Pyrogram's code and not elsewhere
I have searched in the issue tracker for similar bug reports, including closed ones
I ran pip3 install -U https://github.com/pyrogram/pyrogram/archive/master.zip and reproduced the issue using the latest development version
Description
'get_chat' and similar methods throw '[400 USERNAME_INVALID] - The username is invalid (caused by "contacts.ResolveUsername")' with links such as 't.me/channel_link' even though they work correctly when using the username form ('@channel_link')
C:\Users\aradm\AppData\Local\Programs\Python\Python310\python.exe C:/Users/aradm/PycharmProjects/pyrogram/sticker.py
Telegram says: [400 USERNAME_INVALID] - The username is invalid (caused by "contacts.ResolveUsername")
Traceback (most recent call last):
File "C:\Users\aradm\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrogram\methods\advanced\resolve_peer.py", line 60, in resolve_peer
return await self.storage.get_peer_by_id(peer_id)
File "C:\Users\aradm\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrogram\storage\sqlite_storage.py", line 148, in get_peer_by_id
raise KeyError(f"ID not found: {peer_id}")
KeyError: 'ID not found: t.me/varzesh3'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\aradm\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrogram\methods\advanced\resolve_peer.py", line 69, in resolve_peer
int(peer_id)
ValueError: invalid literal forint() with base 10: 't.me/varzesh3'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\aradm\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrogram\methods\advanced\resolve_peer.py", line 72, in resolve_peer
return await self.storage.get_peer_by_username(peer_id)
File "C:\Users\aradm\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrogram\storage\sqlite_storage.py", line 159, in get_peer_by_username
raise KeyError(f"Username not found: {username}")
KeyError: 'Username not found: t.me/varzesh3'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\aradm\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrogram\dispatcher.py", line 242, in handler_worker
await self.loop.run_in_executor(
File "C:\Users\aradm\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "C:\Users\aradm\PycharmProjects\pyrogram\sticker.py", line 9, in respond
chat = client.get_chat('t.me/varzesh3')
File "C:\Users\aradm\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrogram\sync.py", line 78, in async_to_sync_wrap
return asyncio.run_coroutine_threadsafe(coroutine, main_loop).result()
File "C:\Users\aradm\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\_base.py", line 446, in result
returnself.__get_result()
File "C:\Users\aradm\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\_base.py", line 391, in __get_result
raise self._exception
File "C:\Users\aradm\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrogram\methods\chats\get_chat.py", line 76, in get_chat
peer = await self.resolve_peer(chat_id)
File "C:\Users\aradm\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrogram\methods\advanced\resolve_peer.py", line 74, in resolve_peer
await self.invoke(
File "C:\Users\aradm\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrogram\methods\advanced\invoke.py", line 77, in invoke
r = await self.session.invoke(
File "C:\Users\aradm\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrogram\session\session.py", line 361, in invoke
return await self.send(query, timeout=timeout)
File "C:\Users\aradm\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrogram\session\session.py", line 331, in send
RPCError.raise_it(result, type(data))
File "C:\Users\aradm\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrogram\errors\rpc_error.py", line 91, in raise_it
raise getattr(
pyrogram.errors.exceptions.bad_request_400.UsernameInvalid: Telegram says: [400 USERNAME_INVALID] - The username is invalid (caused by "contacts.ResolveUsername")
The text was updated successfully, but these errors were encountered:
When a user has automated reading of chats/channels/groups content or has the message handler active, the links to the channels usually also appear in the following format: "https://t.me/telegram". Right now, we get a 400 error if we want to authenticate using the "https://t.me/telegram" link.
With this improvement in line 70, the user can use either just the public channel nickname or the full link. It makes it easier for the user to use any type of link and he will have no problem accessing it.
With this change, apart from improving the usability of the library, some issues such as "pyrogram#1077" from August 2022 are also fixed.
Checklist
pip3 install -U https://github.com/pyrogram/pyrogram/archive/master.zipand reproduced the issue using the latest development versionDescription
'get_chat' and similar methods throw '[400 USERNAME_INVALID] - The username is invalid (caused by "contacts.ResolveUsername")' with links such as 't.me/channel_link' even though they work correctly when using the username form ('@channel_link')
Steps to reproduce
Code example
Logs
The text was updated successfully, but these errors were encountered: