简体   繁体   English

python pycrypto:模块'对象没有属性'importKey'

[英]python pycrypto: module' object has no attribute 'importKey'

I'm currently working with pycrypto and I want to import public key,but it can not work and raise some error: 'module' object has no attribute 'importKey'' 我目前正在使用pycrypto,并且我想导入公共密钥,但是它无法正常工作并引发一些错误: “模块”对象没有属性“ importKey”
I also use pycrypto in my other script,it works well,so I can not understand why this can not work. 我在其他脚本中也使用pycrypto,它运行良好,所以我不明白为什么它不起作用。
my code that can't work is as following: 我无法正常工作的代码如下:

    from Crypto.PublicKey import RSA
    .............
    .............
    def task_name(task):
        username = task['user']
        taskintid = task['taskintid']
        data = '%s,%s' % (str(username), str(taskintid))
        user_id = task.get('op_user_id', '')
        db = get_db()

        ssh_key = db.ssh_key.find_one({'user_id': user_id})
        if ssh_key:
            try:
                public_key = RSA.importKey(ssh_key.get('ssh_key', ''))
                data = public_key.encrypt(data, 32)[0].encode('hex')
            except Exception, e:
                print e

    return "task-%s-%s" % (data, task['repeat_num'])

also, my python version is 2.6.5 另外,我的python版本是2.6.5
======================================= =======================================
sorry,I forgot it, the pycrypto version is 2.0.1 抱歉,我忘了,pycrypto版本是2.0.1
because I have installed many packages,so I can not upgrage my pycrypto version 因为我已经安装了许多软件包,所以我无法升级我的pycrypto版本

变更日志中列出的2.2版中实现了对导出和导入RSA密钥的支持,因此除非您可以进行升级,否则您很不走运。

我通过pip install pycryptodome解决了这个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 python:即使安装了pycrypto,模块“Crypto.Cipher.AES”也没有属性“MODE_CCM” - python: module 'Crypto.Cipher.AES' has no attribute 'MODE_CCM' even though pycrypto installed Python 2.7“模块”对象没有属性“ setPenRadius” - Python 2.7 'module' object has no attribute 'setPenRadius' Python错误,“'module'对象没有属性'lstrip'” - Python error, “ 'module' object has no attribute 'lstrip' ” Python AttributeError:“模块”对象没有“连接”属性 - Python AttributeError: 'module' object has no attribute 'connect' Python:AttributeError:'module'对象没有属性'AddReference'? - Python: AttributeError: 'module' object has no attribute 'AddReference'? AttributeError:“模块”对象在python中没有属性“ windll” - AttributeError: 'module' object has no attribute 'windll' in python Python 2:AttributeError:“模块”对象没有属性“扫描” - Python 2: AttributeError: 'module' object has no attribute 'scan' Python:AttributeError:“模块”对象没有属性 - Python: AttributeError: 'module' object has no attribute Python:AttributeError:“模块”对象没有属性“附加” - Python: AttributeError: 'module' object has no attribute 'append' python'module'对象没有属性'compile' - python 'module' object has no attribute 'compile'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM