When I am starting my telegram bot by Pyrogram using the latest version v2.0.103
app = Client("BillyKaiChengBot",api_id="apiid",api_hash=os.environ['API'],bot_token=os.environ['TOKEN'])
with app: #error produces here
loginapp = app.send_message(channel_id, "login")
#my own code
#.
#.
#.
app.run()
This code can run smoothly until recently, it produces this error
Traceback (most recent call last):
File "main.py", line 47, in <module>
with app:
File "/home/runner/billy-telegram/venv/lib/python3.8/site-packages/pyrogram/client.py", line 280, in __enter__
return self.start()
File "/home/runner/billy-telegram/venv/lib/python3.8/site-packages/pyrogram/sync.py", line 66, in async_to_sync_wrap
return loop.run_until_complete(coroutine)
File "/nix/store/2vm88xw7513h9pyjyafw32cps51b0ia1-python3-3.8.12/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
File "/home/runner/billy-telegram/venv/lib/python3.8/site-packages/pyrogram/methods/utilities/start.py", line 58, in start
is_authorized = await self.connect()
File "/home/runner/billy-telegram/venv/lib/python3.8/site-packages/pyrogram/methods/auth/connect.py", line 40, in connect
await self.load_session()
File "/home/runner/billy-telegram/venv/lib/python3.8/site-packages/pyrogram/client.py", line 584, in load_session
await Auth(
File "/home/runner/billy-telegram/venv/lib/python3.8/site-packages/pyrogram/session/auth.py", line 254, in create
raise e
File "/home/runner/billy-telegram/venv/lib/python3.8/site-packages/pyrogram/session/auth.py", line 89, in create
res_pq = await self.invoke(raw.functions.ReqPqMulti(nonce=nonce))
File "/home/runner/billy-telegram/venv/lib/python3.8/site-packages/pyrogram/session/auth.py", line 67, in invoke
return self.unpack(response)
File "/home/runner/billy-telegram/venv/lib/python3.8/site-packages/pyrogram/session/auth.py", line 60, in unpack
return TLObject.read(b)
File "/home/runner/billy-telegram/venv/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
I tried to reinstall the module but it not works.
Any help would be appreciated!
2
Answers
According to the owner response in GitHub, the main reason of this issue is caused by server or network issue, not from the code or module itself.
You are combining 2 ways of calling
app.run()
.You should use it like so, where you pass a function to
run
:OR, if you don’t want a
main()
, you can also do:Note that in the second example, there is no
with app
, that’s were your error is coming from. Pick one of those.Both snippets are part of pyrogram’s examples.