Python 2.6 - paramiko导入错误

时间:2014-07-22 12:09:37

标签: python unix python-2.6 paramiko

我有一些脚本在导入cron的{​​{1}}中每30分钟运行一次。看似随意,我会在导入过程中得到这两个错误之一:

paramiko

- 或 -

Traceback (most recent call last):
  ...
  File "build/bdist.linux-x86_64/egg/paramiko/__init__.py", line 65, in <module>
  File "build/bdist.linux-x86_64/egg/paramiko/transport.py", line 42, in <module>
  File "build/bdist.linux-x86_64/egg/paramiko/packet.py", line 39, in <module>
  File "build/bdist.linux-x86_64/egg/Crypto/Hash/HMAC.py", line 66, in <module>
  File "build/bdist.linux-x86_64/egg/Crypto/Util/strxor.py", line 7, in <module>
  File "build/bdist.linux-x86_64/egg/Crypto/Util/strxor.py", line 6, in __bootstrap__
ImportError: dynamic module does not define init function (initstrxor)

每次我看到此问题时,只需重新运行脚本即可正确导入Traceback (most recent call last): ... File "build/bdist.linux-x86_64/egg/paramiko/__init__.py", line 65, in <module> File "build/bdist.linux-x86_64/egg/paramiko/transport.py", line 53, in <module> File "build/bdist.linux-x86_64/egg/Crypto/Cipher/ARC4.py", line 66, in <module> File "build/bdist.linux-x86_64/egg/Crypto/Cipher/_ARC4.py", line 7, in <module> File "build/bdist.linux-x86_64/egg/Crypto/Cipher/_ARC4.py", line 6, in __bootstrap__ ImportError: dynamic module does not define init function (init_ARC4) 并完成脚本。

可能导致此问题的原因是什么?非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

虽然我不知道可能导致错误的原因,但似乎它在pycrypto的原生部分失败了,所以你可能想重试几次:

from time import sleep
n_tries= 3
import_success= False

while not import_success:
    try:
        from Crypto.Cipher import Blowfish, AES, DES3, ARC4
        from Crypto.Hash import MD5, SHA, SHA256, HMAC
        from Crypto import Random
        from Crypto.PublicKey import DSA, RSA
        from Crypto.Util import Counter, number
        import_success= True
    except ImportError:
        if not n_tries:
            raise #re-raise ImportError
        n_tries-=1
        sleep(1)