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

Pyrogram is incompatible with PYTHONOPTIMIZE=2 (or -OO) #1404

Open
3 tasks done
stat1c-void opened this issue Mar 18, 2024 · 0 comments
Open
3 tasks done

Pyrogram is incompatible with PYTHONOPTIMIZE=2 (or -OO) #1404

stat1c-void opened this issue Mar 18, 2024 · 0 comments

Comments

@stat1c-void
Copy link

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

Error handling breaks when run under Python optimize level 2 (env PYTHONOPTIMIZE=2 or -OO command line flag). Seemingly it's because level 2 removes docstrings, and Pyrogram error formatting depends on them.

Ok, I might be weird to run things with -OO. Anyway, it would be nice to mention it in docs, check sys.flags.optimize or something else.

Steps to reproduce

  1. Run Pyrogram app with PYTHONOPTIMIZE=2 or -OO
  2. Encounter any error
  3. See posted traceback

Code example

No response

Logs

Traceback (most recent call last):

- REDACTED -

  File "/usr/local/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "-REDACTED-/services/telegram.py", line 45, in apost_dailies
    async with client:
  File "/usr/src/app/.venv/lib/python3.10/site-packages/pyrogram/client.py", line 311, in __aenter__
    return await self.start()
  File "/usr/src/app/.venv/lib/python3.10/site-packages/pyrogram/methods/utilities/start.py", line 62, in start
    await self.authorize()
  File "/usr/src/app/.venv/lib/python3.10/site-packages/pyrogram/client.py", line 333, in authorize
    return await self.sign_in_bot(self.bot_token)
  File "/usr/src/app/.venv/lib/python3.10/site-packages/pyrogram/methods/auth/sign_in_bot.py", line 51, in sign_in_bot
    r = await self.invoke(
  File "/usr/src/app/.venv/lib/python3.10/site-packages/pyrogram/methods/advanced/invoke.py", line 79, in invoke
    r = await self.session.invoke(
  File "/usr/src/app/.venv/lib/python3.10/site-packages/pyrogram/session/session.py", line 389, in invoke
    return await self.send(query, timeout=timeout)
  File "/usr/src/app/.venv/lib/python3.10/site-packages/pyrogram/session/session.py", line 357, in send
    RPCError.raise_it(result, type(data))
  File "/usr/src/app/.venv/lib/python3.10/site-packages/pyrogram/errors/rpc_error.py", line 91, in raise_it
    raise getattr(
  File "/usr/src/app/.venv/lib/python3.10/site-packages/pyrogram/errors/rpc_error.py", line 46, in __init__
    self.MESSAGE.format(value=value),
AttributeError: 'NoneType' object has no attribute 'format'
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

1 participant