无法从cryptography.hazmat.bindings加载ffi库\u openssl

7kjnsjlb  于 2021-06-18  发布在  Mysql
关注(0)|答案(1)|浏览(448)

我尝试在windows10上打开一个mysql数据库,使用anaconda(python3.7 64位)和pymysql包。
在windows命令提示符下,我执行以下操作:

import pymysql
db = pymysql.connect(host='localhost', user='tester', passwd='xxxx', port=3306, db='mydb')

用户名、密码、端口正确;主机应该是localhost(如果我通过127.0.0.1,我会得到相同的错误);但我得到了以下错误,在最后指出它找不到ffi包:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\programs\Anaconda3\lib\site-packages\pymysql\__init__.py", line 94, in Connect
    return Connection(*args,**kwargs)
  File "C:\programs\Anaconda3\lib\site-packages\pymysql\connections.py", line 327, in __init__
    self.connect()
  File "C:\programs\Anaconda3\lib\site-packages\pymysql\connections.py", line 598, in connect
    self._request_authentication()
  File "C:\programs\Anaconda3\lib\site-packages\pymysql\connections.py", line 873, in _request_authentication
    auth_packet = _auth.caching_sha2_password_auth(self, auth_packet)
  File "C:\programs\Anaconda3\lib\site-packages\pymysql\_auth.py", line 252, in caching_sha2_password_auth
    data = sha2_rsa_encrypt(conn.password, conn.salt, conn.server_public_key)
  File "C:\programs\Anaconda3\lib\site-packages\pymysql\_auth.py", line 132, in sha2_rsa_encrypt
    rsa_key = serialization.load_pem_public_key(public_key, default_backend())
  File "C:\programs\Anaconda3\lib\site-packages\cryptography\hazmat\backends\__init__.py", line 15, in default_backend
    from cryptography.hazmat.backends.openssl.backend import backend
  File "C:\programs\Anaconda3\lib\site-packages\cryptography\hazmat\backends\openssl\__init__.py", line 7, in <module>
    from cryptography.hazmat.backends.openssl.backend import backend
  File "C:\programs\Anaconda3\lib\site-packages\cryptography\hazmat\backends\openssl\backend.py", line 53, in <module>
    from cryptography.hazmat.bindings.openssl import binding
  File "C:\programs\Anaconda3\lib\site-packages\cryptography\hazmat\bindings\openssl\binding.py", line 13, in <module>
    from cryptography.hazmat.bindings._openssl import ffi, lib
ImportError: DLL load failed: The specified module could not be found.

我已经看到condanavigator(nor-pip)没有从标准频道看到ffi包。
我已经尝试过这个建议(添加conda forge频道):
conda config—添加通道conda forge conda install libffi
但康达在“解决环境问题”上花了很长时间,并没有在合理的时间内给出答案。
我该怎么做才能安装ffi并连接到db?我是世界上第一个在windows上从python/anaconda调用mysql的人吗?我想一定有解决办法。
谢谢,马可

oalqel3c

oalqel3c1#

我也遇到了同样的问题。以下是为我解决问题的方法: 1. pip uninstall scrapy 2. conda uninstall scrapy 3. pip install --force --upgrade scrapy 4. scrapy startproject dingding 它起作用了。

相关问题