猎鹰蟒 M2Crypto RSA 错误



我们最近开发了一个使用 RSA 的 API,主要问题是在控制台中它可以正常工作,但一旦进入应用程序的"venv",它就会显示不同的错误。

Traceback (most recent call last):

File "/root/merci_api/venv/lib/python3.5/site-packages/gunicorn/arbiter.py", line 557, in spawn_worker
    worker.init_process()
  File "/root/merci_api/venv/lib/python3.5/site-packages/gunicorn/workers/base.py", line 126, in init_process
    self.load_wsgi()
  File "/root/merci_api/venv/lib/python3.5/site-packages/gunicorn/workers/base.py", line 136, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/root/merci_api/venv/lib/python3.5/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/root/merci_api/venv/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/root/merci_api/venv/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/root/merci_api/venv/lib/python3.5/site-packages/gunicorn/util.py", line 357, in import_app
    __import__(module)
  File "/root/merci_api/main.py", line 12, in <module>
    import transaction_commit
  File "/root/merci_api/transaction_commit.py", line 9, in <module>
    import cfdi
  File "/root/merci_api/cfdi.py", line 15, in <module>
    from M2Crypto import RSA
  File "/root/merci_api/venv/lib/python3.5/site-packages/M2Crypto-0.25.1-py3.5-linux-x86_64.egg/M2Crypto/__init__.py", line 26, in <module>
    from M2Crypto import (ASN1, AuthCookie, BIO, BN, DH, DSA, EVP, Engine, Err,
  File "/root/merci_api/venv/lib/python3.5/site-packages/M2Crypto-0.25.1-py3.5-linux-x86_64.egg/M2Crypto/SSL/__init__.py", line 24, in <module>
    from M2Crypto.SSL.SSLServer import (ForkingSSLServer, SSLServer,
  File "/root/merci_api/venv/lib/python3.5/site-packages/M2Crypto-0.25.1-py3.5-linux-x86_64.egg/M2Crypto/SSL/SSLServer.py", line 12, in <module>
    from SocketServer import BaseServer, ForkingMixIn, TCPServer, ThreadingMixIn
ImportError: No module named 'SocketServer'

M2Crypto库安装在ubuntu和pip中。

使用 RSA 的代码是:

def sella_xml(cfdi, numero_certificado, archivo_cer, archivo_pem):
    keys = RSA.load_key(archivo_pem)
    cert_file = open(archivo_cer, 'r')
    cert = base64.b64encode(cert_file.read())
    xdoc = ET.fromstring(cfdi)
    xsl_root = ET.parse('cadenaoriginal_3_3.xslt')
    xsl = ET.XSLT(xsl_root)
    cadena_original = xsl(xdoc)
    digest = hashlib.new('sha256', str(cadena_original)).digest()
    sello = base64.b64encode(keys.sign(digest, "sha256"))
    comp = xdoc.get('Comprobante')
    xdoc.attrib['Sello'] = sello
    xdoc.attrib['Certificado'] = cert
    return ET.tostring(xdoc)

运行环境命令:

 /root/merci_api/venv/bin/gunicorn --workers 3 -b localhost:5000 main:app

有什么建议吗?

我做错了什么?

好吧,问题是我们安装的版本的 M2Crypto 与 Python 3.* 不兼容,因此当我们使用另一个 M2Crypto 版本时,我们还有另一个问题"SSL v2"来解决我们需要这个。

  • 安装 Python 2.*
  • 直接从存储库安装最新版本的 M2Crypto。
  • 点卸载 -y m2加密
  • pip install git+https://gitlab.com/m2crypto/m2crypto.git

除非你使用python3分支M2Crypto仍然不支持py3k。

相关内容

  • 没有找到相关文章

最新更新