Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on connect #1249

Closed
3 tasks done
AbirHasan2005 opened this issue Apr 7, 2023 · 3 comments
Closed
3 tasks done

Error on connect #1249

AbirHasan2005 opened this issue Apr 7, 2023 · 3 comments

Comments

@AbirHasan2005
Copy link
Contributor

Checklist

  • 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

When I try to start a simple Telegram bot with Bot.run() it tries to connect and after a few retries it gives me error. It's only giving error in this bot. My other bots are working fine. So, is it Pyrogram issue or Telegram Server Side issue?

Hopefully you will give me a solution soon.

Steps to reproduce

  1. make Bot using pyrogram.Client
  2. then Bot.run()

Code example

from pyrogram import Client, filters

Bot = Client("pyro", api_id=..., api_hash=..., bot_token=..., in_memory=True)


@Bot.on_message(filters=filters.command("start"))
async def start_cmd(_, m):
    await m.reply_text("Hi", True)


# Some project codes here
...

Bot.run()

Logs

__main__ - INFO - Starting Bot ...
pyrogram.session.auth - INFO - Start creating a new auth key on DC2
pyrogram.connection.connection - INFO - Connecting...
pyrogram.connection.connection - INFO - Connected! Production DC2 - IPv4
pyrogram.session.auth - INFO - Retrying due to KeyError: 0
pyrogram.connection.connection - INFO - Disconnected
pyrogram.session.auth - INFO - Start creating a new auth key on DC2
pyrogram.connection.connection - INFO - Connecting...
pyrogram.connection.connection - INFO - Connected! Production DC2 - IPv4
pyrogram.session.auth - INFO - Retrying due to KeyError: 0
pyrogram.connection.connection - INFO - Disconnected
pyrogram.session.auth - INFO - Start creating a new auth key on DC2
pyrogram.connection.connection - INFO - Connecting...
pyrogram.connection.connection - INFO - Connected! Production DC2 - IPv4
pyrogram.session.auth - INFO - Retrying due to KeyError: 0
pyrogram.connection.connection - INFO - Disconnected
pyrogram.session.auth - INFO - Start creating a new auth key on DC2
pyrogram.connection.connection - INFO - Connecting...
pyrogram.connection.connection - INFO - Connected! Production DC2 - IPv4
pyrogram.session.auth - INFO - Retrying due to KeyError: 0
pyrogram.connection.connection - INFO - Disconnected
pyrogram.session.auth - INFO - Start creating a new auth key on DC2
pyrogram.connection.connection - INFO - Connecting...
pyrogram.connection.connection - INFO - Connected! Production DC2 - IPv4
pyrogram.session.auth - INFO - Retrying due to KeyError: 0
pyrogram.connection.connection - INFO - Disconnected
pyrogram.session.auth - INFO - Start creating a new auth key on DC2
pyrogram.connection.connection - INFO - Connecting...
pyrogram.connection.connection - INFO - Connected! Production DC2 - IPv4
pyrogram.session.auth - INFO - Retrying due to KeyError: 0
pyrogram.connection.connection - INFO - Disconnected
Traceback (most recent call last):
  File "bot.py", line 441, in <module>
    Bot.run()
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pyrogram/methods/utilities/run.py", line 84, in run
    self.start()
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pyrogram/sync.py", line 66, in async_to_sync_wrap
    return loop.run_until_complete(coroutine)
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pyrogram/methods/utilities/start.py", line 58, in start
    is_authorized = await self.connect()
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pyrogram/methods/auth/connect.py", line 40, in connect
    await self.load_session()
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pyrogram/client.py", line 637, in load_session
    await Auth(
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pyrogram/session/auth.py", line 274, in create
    raise e
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pyrogram/session/auth.py", line 89, in create
    res_pq = await self.invoke(raw.functions.ReqPqMulti(nonce=nonce))
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pyrogram/session/auth.py", line 67, in invoke
    return self.unpack(response)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pyrogram/session/auth.py", line 60, in unpack
    return TLObject.read(b)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pyrogram/raw/core/tl_object.py", line 33, in read
    return cast(TLObject, objects[int.from_bytes(b.read(4), "little")]).read(b, *args)
KeyError: 0
@LucasID26
Copy link

ohh I also experienced the same thing

@delivrance
Copy link
Member

The issue is related to empty responses received from the server and is not reproducible consistently. It's very likely just a momentary server or network issue.

@binary1Ne
Copy link

Hi @LucasID26 Please confirm, Is that Issue resolved , Because I am getting this issue for quite some time now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants