Skip to content

[QUESTION] ImportError: cannot import name 'AsymmetricPadding' #2368

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

Closed
k-vishnevsky opened this issue Feb 8, 2021 · 2 comments
Closed

[QUESTION] ImportError: cannot import name 'AsymmetricPadding' #2368

k-vishnevsky opened this issue Feb 8, 2021 · 2 comments
Labels

Comments

@k-vishnevsky
Copy link

k-vishnevsky commented Feb 8, 2021

Issue I am facing

Receiving this error

ImportError: cannot import name 'AsymmetricPadding' from partially initialized module 'cryptography.hazmat.primitives.asymmetric.padding' (most likely due to a circular import) (/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/cryptography/hazmat/primitives/asymmetric/padding.py)

in this official example script.

python-telegram-bot 13.2
Python v3.9.1
pip v20.2.3
MacOS v11.1 (20C69)

Traceback to the issue

Traceback (most recent call last):
  File "/Users/kirill/devbox/media_capture_bot/main.py", line 3, in <module>
    from telegram import Update
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/telegram/__init__.py", line 51, in <module>
    from .files.file import File
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/telegram/files/file.py", line 28, in <module>
    from telegram.passport.credentials import decrypt
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/telegram/passport/credentials.py", line 29, in <module>
    from cryptography.hazmat.primitives.asymmetric.padding import MGF1, OAEP
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/cryptography/hazmat/primitives/asymmetric/padding.py", line 10, in <module>
    from cryptography.hazmat.primitives.asymmetric import rsa
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.py", line 20, in <module>
    from cryptography.hazmat.primitives.asymmetric.padding import AsymmetricPadding
ImportError: cannot import name 'AsymmetricPadding' from partially initialized module 'cryptography.hazmat.primitives.asymmetric.padding' (most likely due to a circular import) (/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/cryptography/hazmat/primitives/asymmetric/padding.py)

Related part of your code

import logging

from telegram import Update
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext

# Enable logging
logging.basicConfig(
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO
)

logger = logging.getLogger(__name__)


# Define a few command handlers. These usually take the two arguments update and
# context. Error handlers also receive the raised TelegramError object in error.
def start(update: Update, context: CallbackContext) -> None:
    """Send a message when the command /start is issued."""
    update.message.reply_text('Hi!')


def help_command(update: Update, context: CallbackContext) -> None:
    """Send a message when the command /help is issued."""
    update.message.reply_text('Help!')


def echo(update: Update, context: CallbackContext) -> None:
    """Echo the user message."""
    update.message.reply_text(update.message.text)


def main():
    """Start the bot."""
    # Create the Updater and pass it your bot's token.
    updater = Updater("<my Telegram bot token here>")

    # Get the dispatcher to register handlers
    dispatcher = updater.dispatcher

    # on different commands - answer in Telegram
    dispatcher.add_handler(CommandHandler("start", start))
    dispatcher.add_handler(CommandHandler("help", help_command))

    # on noncommand i.e message - echo the message on Telegram
    dispatcher.add_handler(MessageHandler(Filters.text & ~Filters.command, echo))

    # Start the Bot
    updater.start_polling()

    # Run the bot until you press Ctrl-C or the process receives SIGINT,
    # SIGTERM or SIGABRT. This should be used most of the time, since
    # start_polling() is non-blocking and will stop the bot gracefully.
    updater.idle()


if __name__ == '__main__':
    main()

Thanks in advance!

@Bibo-Joshi
Copy link
Member

Hi. This is due to a bug in the 3.4 release of cryptography. They already released v3.4.1, which fixes that bug. Please upgrade via pip install -U cryptography. We'll adjust our requirements to skip that version.

@k-vishnevsky
Copy link
Author

k-vishnevsky commented Feb 8, 2021

Thanks a ton, @Bibo-Joshi, problem solved!

@github-actions github-actions bot locked and limited conversation to collaborators Feb 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants