Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

"from Crypto.Cipher import AES" fails #632

Unanswered
moryoav asked this question in General
Discussion options

I'm not sure if I'm doing something wrong here. My py script has "from Crypto.Cipher import AES" which fails.

The error in the log is:

from Crypto.Cipher import AES
^
AttributeError: module 'Crypto.Cipher' has no attribute 'AES'

I created a requirements.txt in the the pyscript folder and in it:

pycryptodome==3.2

I look at the source files (https://pypi.org/project/pycryptodome/#files) and I see that it should include the AES attribute inside Crypto.Cipher. The same code works fine on my computer, so I know the import should work.

Other imports work fine. "Allow All Imports" is selected.

Any assistance will be greatly appreciated...

Thanks.

You must be logged in to vote

Replies: 4 comments 3 replies

Comment options

try this structure:
image
then in pyscript/config.yaml

allow_all_imports: true
apps:
 air_raid_alarm:
You must be logged in to vote
2 replies
Comment options

I get the exact same error.

from Crypto.Cipher import AES
^
AttributeError: module 'Crypto.Cipher' has no attribute ['AES']

I'm attaching the code and the folder.

decrypt_whatsapp_media.zip

Comment options

my second guess is that HA Core has this prerequisite of the exact version 3.6.6 https://github.com/search?q=repo%3Ahome-assistant%2Fcore%20pycryptodome&type=code and you are trying to expect the latest 3.20.0, which can be achieved only by adding pycryptodome==3.20.0 in your requirements.txt, but this can lead to exceptions in HA Core that relies on the lower verison.

Comment options

pycryptodome version 3.6.6 should also work, and it also has the AES attribute (I looked at the source here: https://pypi.org/project/pycryptodome/3.6.6/#files), I changed the requirements.txt to "pycryptodome==3.6.6" (or perhaps it's not needed at all now), but I still get the same error.

You must be logged in to vote
1 reply
Comment options

3.6.6 does not work for me, but with a different error
image

Comment options

Another interesting thing, if I use "pycryptodomex" instead (I see I also don't need it in the requirements, it tells me it's included), then I also can't do "from Cryptodome.Cipher import AES" for some reason.

You must be logged in to vote
0 replies
Comment options

I took the entire Crypto package from GitHub (which has an attribute for AES) and renamed Crypto to Crypto2.
Then, I did a find & replace on all the files inside this package to replace the import Crypto into import Crypto2.
I placed the entire package in pyscript/modules/Crypto2 folder.
If I do from Crypto2.Cipher import AES I get a ton of errors about file is not defined. I feel like I'm close.
The package is attached.

Crypto2.zip

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /