python - 尝试运行密码时出现错误 : "module ' hashlib' has no attribute 'scrypt' "

标签 python cryptography hashlib

正如我在标题中提到的,我正在尝试使用这个简单的代码来运行库密码:

import cryptocode

password = "This is a test"
key = "My Key"


def encrypt(password, key):
    return cryptocode.encrypt(password, key)


def decrypt(encryptetpass):
    return cryptocode.decrypt(encryptetpass, key)


encrypted_pass = encrypt(password, key)
print(encrypted_pass)

print(decrypt(encrypted_pass))

在 Windows 上本地运行它时,我没有收到任何错误,但在 Linux 上尝试同样的操作会产生前面标题中提到的错误:

(venv) pwd$ python3.9 crypt_test.py

Traceback (most recent call last):
  File "/crypt_test.py", line 15, in <module>
    encrypted_pass = encrypt(password, key)
  File "/crypt_test.py", line 8, in encrypt
    return cryptocode.encrypt(password, key)
  File "/venv/lib/python3.9/site-packages/cryptocode/myfunctions.py", line 16, in encrypt
    private_key = hashlib.scrypt(
AttributeError: module 'hashlib' has no attribute 'scrypt'

我尝试更新 Openssl,重新安装我的 venv 和 Python。

最佳答案

检查以下几点:

检查安装了哪些版本

which python

//use python or python3 as per your needs

检查所有版本的安装位置

where python

//use python or python3 as per your needs

在我的例子中,我有如下两条路径,

/usr/bin/python 
/usr/local/bin/python

所以,现在检查 VS Code,

  • 命令 + Shipt + P
  • 搜索/选择 Python 解释器
  • 选择您正在使用的适当版本,如果未列出,请添加相应的路径并选择相同的路径。

这个解决方案对我有用:)

关于python - 尝试运行密码时出现错误 : "module ' hashlib' has no attribute 'scrypt' ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69204547/

相关文章:

Python hashlib 没有为 md5 生成正确的哈希值

python - 从网站读取 .tar.gz 文件的内容到 python 3.x 对象中

python - 在 mongoDB 中求和数组大小字段的最佳方法

javascript - 当 openssl 命令行执行时,Node.js 验证功能不验证签名

cryptography - openssl 生成的私钥不满足 n = p * q

java - Python 等效于 java PBKDF2WithHmacSHA1

python - sha 模块已弃用

python - 类型错误 - 无法将 'User' 对象隐式转换为 str

Python 学习。为什么我只在第一次收到警告?

java - 无法以 AES 加密/解密中的字符串形式获取解密文件