You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
I've tried several times with different groups and users to obtain information about a chat using pyrogram.Client.get_chat() method, and simply passing a username to the method's chat_id argument works, whereas passing the username as a link instead raises the error.
I've researched the issue, and it seems that another person had run into the same issue, which remains unresolved > the issue.
The doc string of the get_chat()says that a link is a valid input format:
...
Parameters:
chat_id (``int`` | ``str``):
Unique identifier (int) or username (str) of the target chat.
Unique identifier for the target chat in form of a *t.me/joinchat/* link, identifier (int) or username
of the target channel/supergroup (in the format @username)
...
Steps to reproduce
Use a valid telegram username:
Pass "<username>" to the chat_id argument, and try to run the coroutine, check the output.
Repeat the first step, but instead of "<username>" try passing "https://t.me/<username>" or "t.me/<username>"
Code example
################peer=awaitclient.get_chat('pyrogramchat')
print("Chat ID:", peer.id)
"""The Output:Chat ID: -1001387666944"""################# Try this instead:################peer=awaitclient.get_chat('t.me/pyrogramchat') # The output is in the 'Logs' section.################
Logs
Telegram says: [400 USERNAME_INVALID] - The username is invalid (caused by "contacts.ResolveUsername")
Traceback (most recent call last):
File "/home/eliot/Documents/development/userBots/vovaTroll/venv/lib/python3.8/site-packages/pyrogram/methods/advanced/resolve_peer.py", line 62, in resolve_peer
return await self.storage.get_peer_by_id(peer_id)
File "/home/eliot/Documents/development/userBots/vovaTroll/venv/lib/python3.8/site-packages/pyrogram/storage/sqlite_storage.py", line 142, in get_peer_by_id
raise KeyError(f"ID not found: {peer_id}")
KeyError: 'ID not found: t.me/pyrogramchat'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/eliot/Documents/development/userBots/vovaTroll/venv/lib/python3.8/site-packages/pyrogram/methods/advanced/resolve_peer.py", line 71, in resolve_peer
int(peer_id)
ValueError: invalid literal forint() with base 10: 't.me/pyrogramchat'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/eliot/Documents/development/userBots/vovaTroll/venv/lib/python3.8/site-packages/pyrogram/methods/advanced/resolve_peer.py", line 74, in resolve_peer
return await self.storage.get_peer_by_username(peer_id)
File "/home/eliot/Documents/development/userBots/vovaTroll/venv/lib/python3.8/site-packages/pyrogram/storage/sqlite_storage.py", line 154, in get_peer_by_username
raise KeyError(f"Username not found: {username}")
KeyError: 'Username not found: t.me/pyrogramchat'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/eliot/Documents/development/userBots/vovaTroll/venv/lib/python3.8/site-packages/pyrogram/dispatcher.py", line 240, in handler_worker
await handler.callback(self.client, *args)
File "vova.py", line 17, in hello
peer = await client.get_chat('t.me/pyrogramchat')
File "/home/eliot/Documents/development/userBots/vovaTroll/venv/lib/python3.8/site-packages/pyrogram/methods/chats/get_chat.py", line 78, in get_chat
peer = await self.resolve_peer(chat_id)
File "/home/eliot/Documents/development/userBots/vovaTroll/venv/lib/python3.8/site-packages/pyrogram/methods/advanced/resolve_peer.py", line 76, in resolve_peer
await self.invoke(
File "/home/eliot/Documents/development/userBots/vovaTroll/venv/lib/python3.8/site-packages/pyrogram/methods/advanced/invoke.py", line 79, in invoke
r = await self.session.invoke(
File "/home/eliot/Documents/development/userBots/vovaTroll/venv/lib/python3.8/site-packages/pyrogram/session/session.py", line 389, in invoke
return await self.send(query, timeout=timeout)
File "/home/eliot/Documents/development/userBots/vovaTroll/venv/lib/python3.8/site-packages/pyrogram/session/session.py", line 357, in send
RPCError.raise_it(result, type(data))
File "/home/eliot/Documents/development/userBots/vovaTroll/venv/lib/python3.8/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:
Checklist
pip3 install -U https://github.com/pyrogram/pyrogram/archive/master.zipand reproduced the issue using the latest development versionDescription
I've tried several times with different groups and users to obtain information about a chat using
pyrogram.Client.get_chat()method, and simply passing a username to the method'schat_idargument works, whereas passing the username as a link instead raises the error.I've researched the issue, and it seems that another person had run into the same issue, which remains unresolved > the issue.
The doc string of the
get_chat()says that a link is a valid input format:Steps to reproduce
Use a valid telegram username:
"<username>"to thechat_idargument, and try to run the coroutine, check the output."<username>"try passing"https://t.me/<username>"or"t.me/<username>"Code example
Logs
The text was updated successfully, but these errors were encountered: