python的密码抛出AttributeError:'int'对象没有属性'value' [英] python's cryptography throwing AttributeError: 'int' object has no attribute 'value'

查看:489
本文介绍了python的密码抛出AttributeError:'int'对象没有属性'value'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行以下代码:

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

获取:

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

文件路径为:my_project / utils / encryption.py

The file path is: my_project/utils/encryption.py

在'utils'包之外或在python控制台中运行相同的代码即可正常工作。
可能是什么问题?

Running the same code outside the 'utils' package or in python console works fine. What could be the issue?

推荐答案

加密代码需要Python 3枚举: https://pypi.python.org/pypi/enum34 。这就是为什么出现此问题的原因。

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.

这篇关于python的密码抛出AttributeError:'int'对象没有属性'value'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆