我在Red Hat 6.4上运行python 2.6
我使用paramiko sftp在一台机器上运行了一个脚本。当我将它转移到另一台机器时,我得到了一个例外:SFTP file has no attribute __exit__
(沿着这些路线)。
我决定用pip升级paramiko(认为它可以解决问题)。现在我在运行python脚本时得到这个:
...
File "/usr/lib/python2.6/site-packages/paramiko/__init__.py", line 64, in <module>
from transport import SecurityOptions, Transport
File "/usr/lib/python2.6/site-packages/paramiko/transport.py", line 33, in <module>
from paramiko import util
File "/usr/lib/python2.6/site-packages/paramiko/util.py", line 33, in <module>
from paramiko.common import *
File "/usr/lib/python2.6/site-packages/paramiko/common.py", line 98, in <module>
from Crypto import Random
File "/usr/lib64/python2.6/site-packages/Crypto/Random/__init__.py", line 29, in <module>
from Crypto.Random import _UserFriendlyRNG
File "/usr/lib64/python2.6/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 38, in <module>
from Crypto.Random.Fortuna import FortunaAccumulator
File "/usr/lib64/python2.6/site-packages/Crypto/Random/Fortuna/FortunaAccumulator.py", line 39, in <module>
import FortunaGenerator
File "/usr/lib64/python2.6/site-packages/Crypto/Random/Fortuna/FortunaGenerator.py", line 34, in <module>
from Crypto.Util.number import ceil_shift, exact_log2, exact_div
File "/usr/lib64/python2.6/site-packages/Crypto/Util/number.py", line 56, in <module>
if _fastmath is not None and not _fastmath.HAVE_DECL_MPZ_POWM_SEC:
AttributeError: 'module' object has no attribute 'HAVE_DECL_MPZ_POWM_SEC'
所以帮助!!
答案 0 :(得分:18)
您的系统中似乎安装了多个PyCrypto库。 PyCrypto trackiong系统上的这个bug report似乎是相关的:
我的猜测是你在系统范围内安装了python-crypto-2.0.1 RPM, 并且当你构建和安装时没有安装gmp-devel;安装了以后 PyCrypto的版本,所以你使用的是更新版本的PyCrypto 旧版的_fastmath。
您可以尝试按照建议进行操作:安装gmp-devel
软件包,然后使用pip
安装PyCrypto。
答案 1 :(得分:14)
对我来说,问题是我通过yum安装了python-crypto包,然后还通过pip安装了pycrypto模块。
yum remove python-crypto
为我工作。
答案 2 :(得分:4)
This one可以更好地了解错误本身。
一些开发人员认为提供有关潜在安全威胁的用户友好警告是一个好主意,但是会破坏打印该警告的代码。
我刚刚取代了这个:
# You need libgmp v5 or later to get mpz_powm_sec. Warn if it's not available.
if _fastmath is not None and not _fastmath.HAVE_DECL_MPZ_POWM_SEC:
_warn("Not using mpz_powm_sec. You should rebuild using libgmp >= 5 to avoid timing attack vulnerability.", PowmInsecureWarning)
用这个:
# You need libgmp v5 or later to get mpz_powm_sec. Warn if it's not available.
if _fastmath is not None and not hasattr(_fastmath, 'HAVE_DECL_MPZ_POWM_SEC'):
_warn("Not using mpz_powm_sec. You should rebuild using libgmp >= 5 to avoid timing attack vulnerability.", PowmInsecureWarning)
在我的/usr/lib64/python2.6/site-packages/Crypto/Util/number.py
它仍然可以做得更好,但如果你不关心安全威胁,这将让你前进。
答案 3 :(得分:1)
如果(像我一样)您无法访问number.py,则以下内容可能有所帮助:
import Crypto.PublicKey._fastmath
Crypto.PublicKey._fastmath.HAVE_DECL_MPZ_POWM_SEC=False
之前添加以忽略警告:
import warnings
from Crypto.pct_warnings import PowmInsecureWarning
warnings.simplefilter("ignore", PowmInsecureWarning)
答案 4 :(得分:0)
你可以找到档案:/usr/lib/python2.7/site-packages/Crypto/Util/number.py
内容:
if _fastmath is not None and not _fastmath.HAVE_DECL_MPZ_POWM_SEC:
然后,您可以注释此行,如
#if _fastmath is not None and not _fastmath.HAVE_DECL_MPZ_POWM_SEC:
你可以导入paramiko