AttributeError:模块“时间”在Python 3.8中没有属性“时钟”


23

我已经编写了生成公共和私有密钥的代码。它在Python 3.7上运行良好,但在Python 3.8中失败。我不知道在最新版本中它怎么会失败。为我提供一些解决方案。

这是代码:

from Crypto.PublicKey import RSA


def generate_keys():
    modulus_length = 1024
    key = RSA.generate(modulus_length)
    pub_key = key.publickey()
    private_key = key.exportKey()
    public_key = pub_key.exportKey()
    return private_key, public_key


a = generate_keys()
print(a)

Python 3.8版本中的错误:

Traceback (most recent call last):
  File "temp.py", line 18, in <module>
    a = generate_keys()
  File "temp.py", line 8, in generate_keys
    key = RSA.generate(modulus_length)
  File "/home/paulsteven/.local/lib/python3.8/site-packages/Crypto/PublicKey/RSA.py", line 508, in generate
    obj = _RSA.generate_py(bits, rf, progress_func, e)    # TODO: Don't use legacy _RSA module
  File "/home/paulsteven/.local/lib/python3.8/site-packages/Crypto/PublicKey/_RSA.py", line 50, in generate_py
    p = pubkey.getStrongPrime(bits>>1, obj.e, 1e-12, randfunc)
  File "/home/paulsteven/.local/lib/python3.8/site-packages/Crypto/Util/number.py", line 282, in getStrongPrime
    X = getRandomRange (lower_bound, upper_bound, randfunc)
  File "/home/paulsteven/.local/lib/python3.8/site-packages/Crypto/Util/number.py", line 123, in getRandomRange
    value = getRandomInteger(bits, randfunc)
  File "/home/paulsteven/.local/lib/python3.8/site-packages/Crypto/Util/number.py", line 104, in getRandomInteger
    S = randfunc(N>>3)
  File "/home/paulsteven/.local/lib/python3.8/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 202, in read
    return self._singleton.read(bytes)
  File "/home/paulsteven/.local/lib/python3.8/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 178, in read
    return _UserFriendlyRNG.read(self, bytes)
  File "/home/paulsteven/.local/lib/python3.8/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 129, in read
    self._ec.collect()
  File "/home/paulsteven/.local/lib/python3.8/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 77, in collect
    t = time.clock()
AttributeError: module 'time' has no attribute 'clock'

此处在Crytpo库中引用:github.com/dlitz/pycrypto/issues/283但该票似乎已经有一年没有关闭了。
Fabien Antoine

Answers:




0
AttributeError: module 'time' has no attribute 'clock' 

据说它已弃用,这意味着仅使用具有该模块的最新版本的库。例如,根据您具有的依赖性,删除并安装

Crypto == 1.4.1,或者Mako == 1.1.2或SQLAlchemy == 1.3.6 //等等

这样做的目的是您不必降级python版本,因为以后会跟上您的进度。只需将软件包更新为与Python 3.8兼容的较新的软件包

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.