Reputation: 99
I'm trying to execute the following code:
from cryptography.fernet import Fernet
key = Fernet.generate_key()
cipher_suite = Fernet(key)
cipher_text = cipher_suite.encrypt(b"A really secret message. Not for prying eyes.")
plain_text = cipher_suite.decrypt(cipher_text)
print plain_text
Getting:
C:\Python27\python.exe E:/PycharmProjects/my_project/utils/encryption.py
Traceback (most recent call last):
File "E:/PycharmProjects/my_project/utils/encryption.py", line 3, in <module>
cipher_suite = Fernet(key)
File "C:\Python27\lib\site-packages\cryptography\fernet.py", line 32, in __init__
backend = default_backend()
File "C:\Python27\lib\site-packages\cryptography\hazmat\backends\__init__.py", line 15, in default_backend
from cryptography.hazmat.backends.openssl.backend import backend
File "C:\Python27\lib\site-packages\cryptography\hazmat\backends\openssl\__init__.py", line 7, in <module>
from cryptography.hazmat.backends.openssl.backend import backend
File "C:\Python27\lib\site-packages\cryptography\hazmat\backends\openssl\backend.py", line 16, in <module>
from cryptography import utils, x509
File "C:\Python27\lib\site-packages\cryptography\x509\__init__.py", line 8, in <module>
from cryptography.x509.base import (
File "C:\Python27\lib\site-packages\cryptography\x509\base.py", line 16, in <module>
from cryptography.x509.extensions import Extension, ExtensionType
File "C:\Python27\lib\site-packages\cryptography\x509\extensions.py", line 24, in <module>
from cryptography.x509.general_name import GeneralName, IPAddress, OtherName
File "C:\Python27\lib\site-packages\cryptography\x509\general_name.py", line 18, in <module>
from cryptography.x509.name import Name
File "C:\Python27\lib\site-packages\cryptography\x509\name.py", line 28, in <module>
_ASN1_TYPE_TO_ENUM = dict((i.value, i) for i in _ASN1Type)
File "C:\Python27\lib\site-packages\cryptography\x509\name.py", line 28, in <genexpr>
_ASN1_TYPE_TO_ENUM = dict((i.value, i) for i in _ASN1Type)
AttributeError: 'int' object has no attribute 'value'
Process finished with exit code 1
The file path is: my_project/utils/encryption.py
Running the same code outside the 'utils' package or in python console works fine. What could be the issue?
Upvotes: 0
Views: 1354
Reputation: 4379
The cryptography code needs the Python 3 enum: https://pypi.python.org/pypi/enum34 . That is why you got that issue.
I suggest to verify if your version is right and not replaced by another module as well.
Upvotes: 2
Reputation: 99
The issue was that I had a module named enum.py along with the cryptography code (same package). cryptography tried to use it instead of enum34. Renaming the 'enum.py' to something else solved it.
Upvotes: 0