Pyrogram network issue

Question: Hi it’s been about three days that my code is not working and giving out this error and I looked up other posts like who had the same problem but the solutions given or not working (kill the section with kill 1 and etc) from what it’s seems like it’s a connection issue from Replit because at first the error just fixed it self for a day or two after being offline for a period of time

Repl link:

File "/home/runner/File-Sharing-Bot/main.py", line 6, in <module>
    Bot().run()
  File "/home/runner/File-Sharing-Bot/venv/lib/python3.10/site-packages/pyrogram/methods/utilities/run.py", line 80, in run
    run(self.start())
  File "/nix/store/hd4cc9rh83j291r5539hkf6qd8lgiikb-python3-3.10.8/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/home/runner/File-Sharing-Bot/bot.py", line 40, in start
    await super().start()
  File "/home/runner/File-Sharing-Bot/venv/lib/python3.10/site-packages/pyrogram/methods/utilities/start.py", line 58, in start
    is_authorized = await self.connect()
  File "/home/runner/File-Sharing-Bot/venv/lib/python3.10/site-packages/pyrogram/methods/auth/connect.py", line 40, in connect
    await self.load_session()
  File "/home/runner/File-Sharing-Bot/venv/lib/python3.10/site-packages/pyrogram/client.py", line 586, in load_session
    await Auth(
  File "/home/runner/File-Sharing-Bot/venv/lib/python3.10/site-packages/pyrogram/session/auth.py", line 254, in create
    raise e
  File "/home/runner/File-Sharing-Bot/venv/lib/python3.10/site-packages/pyrogram/session/auth.py", line 89, in create
    res_pq = await self.invoke(raw.functions.ReqPqMulti(nonce=nonce))
  File "/home/runner/File-Sharing-Bot/venv/lib/python3.10/site-packages/pyrogram/session/auth.py", line 67, in invoke
    return self.unpack(response)
  File "/home/runner/File-Sharing-Bot/venv/lib/python3.10/site-packages/pyrogram/session/auth.py", line 60, in unpack
    return TLObject.read(b)
  File "/home/runner/File-Sharing-Bot/venv/lib/python3.10/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
2 Likes

I think there’s a problem accessing a key in a dictionary in bot.py on line 40. Also make sure the bot has its needed permisions. make sure the CHANNEL_ID value in your configuration file is correct and corresponds to a valid channel ID. Try writing some error handling for line 34 to see what the issue is.

2 Likes
from pyrogram import Client, filters

api_id = 123456
api_hash = "165dfdf564df564d4f4f"
bot_token = "1234560:444adsadsadd4wd46d4wadwa"

app = Client(
    "my_bot",
    api_id=api_id, api_hash=api_hash,
    bot_token=bot_token
)

@app.on_message(filters.text & filters.private)
async def echo(client, message):
    await message.reply(message.text)

print("Bot Avviato")
app.run()

stesso error

Bot Avviato
Traceback (most recent call last):
  File "main.py", line 18, in <module>
    app.run()
  File "/home/runner/test-pyrogram/venv/lib/python3.10/site-packages/pyrogram/methods/utilities/run.py", line 84, in run
    self.start()
  File "/home/runner/test-pyrogram/venv/lib/python3.10/site-packages/pyrogram/sync.py", line 66, in async_to_sync_wrap
    return loop.run_until_complete(coroutine)
  File "/nix/store/hd4cc9rh83j291r5539hkf6qd8lgiikb-python3-3.10.8/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/home/runner/test-pyrogram/venv/lib/python3.10/site-packages/pyrogram/methods/utilities/start.py", line 58, in start
    is_authorized = await self.connect()
  File "/home/runner/test-pyrogram/venv/lib/python3.10/site-packages/pyrogram/methods/auth/connect.py", line 40, in connect
    await self.load_session()
  File "/home/runner/test-pyrogram/venv/lib/python3.10/site-packages/pyrogram/client.py", line 637, in load_session
    await Auth(
  File "/home/runner/test-pyrogram/venv/lib/python3.10/site-packages/pyrogram/session/auth.py", line 274, in create
    raise e
  File "/home/runner/test-pyrogram/venv/lib/python3.10/site-packages/pyrogram/session/auth.py", line 89, in create
    res_pq = await self.invoke(raw.functions.ReqPqMulti(nonce=nonce))
  File "/home/runner/test-pyrogram/venv/lib/python3.10/site-packages/pyrogram/session/auth.py", line 67, in invoke
    return self.unpack(response)
  File "/home/runner/test-pyrogram/venv/lib/python3.10/site-packages/pyrogram/session/auth.py", line 60, in unpack
    return TLObject.read(b)
  File "/home/runner/test-pyrogram/venv/lib/python3.10/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
1 Like

From searching on google, this actually means that it couldn’t connect to telegram. KeyError: 0 is a connection error in this case.

2 Likes

oh, my apologies. I’m going to look into why that’s happening

1 Like

they are bots that always worked, the api id, hash and token are correct

2 Likes

Try running kill 1 in the shell so it gets assigned a new IP, and maybe it can connect.

1 Like

tried, still the same error

1 Like

Does changing your server location work?

2 Likes

try pip install --upgrade pyrogram

Double-check that the api_id , api_hash , and bot_token values in your code are correct and make sure your using the right bot account if you have several.

1 Like

the data is correct, the same code started on a vps goes, before it also went on replit but for about a week the bots in pyrogram have stopped running

1 Like

how can i change it?

1 Like

is it giving you any error messages?

1 Like
Traceback (most recent call last):
  File "main.py", line 18, in <module>
    app.run()
  File "/home/runner/test-pyrogram/venv/lib/python3.10/site-packages/pyrogram/methods/utilities/run.py", line 84, in run
    self.start()
  File "/home/runner/test-pyrogram/venv/lib/python3.10/site-packages/pyrogram/sync.py", line 66, in async_to_sync_wrap
    return loop.run_until_complete(coroutine)
  File "/nix/store/hd4cc9rh83j291r5539hkf6qd8lgiikb-python3-3.10.8/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/home/runner/test-pyrogram/venv/lib/python3.10/site-packages/pyrogram/methods/utilities/start.py", line 58, in start
    is_authorized = await self.connect()
  File "/home/runner/test-pyrogram/venv/lib/python3.10/site-packages/pyrogram/methods/auth/connect.py", line 40, in connect
    await self.load_session()
  File "/home/runner/test-pyrogram/venv/lib/python3.10/site-packages/pyrogram/client.py", line 637, in load_session
    await Auth(
  File "/home/runner/test-pyrogram/venv/lib/python3.10/site-packages/pyrogram/session/auth.py", line 274, in create
    raise e
  File "/home/runner/test-pyrogram/venv/lib/python3.10/site-packages/pyrogram/session/auth.py", line 89, in create
    res_pq = await self.invoke(raw.functions.ReqPqMulti(nonce=nonce))
  File "/home/runner/test-pyrogram/venv/lib/python3.10/site-packages/pyrogram/session/auth.py", line 67, in invoke
    return self.unpack(response)
  File "/home/runner/test-pyrogram/venv/lib/python3.10/site-packages/pyrogram/session/auth.py", line 60, in unpack
    return TLObject.read(b)
  File "/home/runner/test-pyrogram/venv/lib/python3.10/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
3 Likes

if its an issue with the Pyrogram library, you could try a VPN

1 Like

I also started the bot with a vpn but the result doesn’t change

1 Like

You will find it here https://replit.com/account as “server location”

2 Likes

changed server location but same error, only for pyrogram library other libraries work, just tried telebot

1 Like

Did you try kill 1 after changing location?

1 Like

i changed server location from america to asia and did in shell kill 1 and on that bot it started. I’ve tried starting other bots and they don’t go immediately after killing 1. Do I have to rewrite them from scratch?

1 Like