Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ffi library can't be loaded from cryptography.hazmat.bindings._openssl

I'm trying to open a mysql database on windows 10, with anaconda (python 3.7 64 bit) and the pymysql package.

From windows command prompt, I do the following :

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

Username, password and port are correct; the host should be localhost (I get the same error if I pass 127.0.0.1); but I get the following error, which at the end states that it can't find the ffi package:

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.

I've seen that conda navigator (nor pip) doesn't see an ffi package from its standard channels.

I have already tried this suggestion (adding the conda-forge channel) :

conda config --add channels conda-forge conda install libffi

but conda takes forever in "solving environment" and doesn't give answers in reasonable time.

What am I supposed to do to install ffi and being able to connect to the db ? Am I the first in the world in calling mysql from python/Anaconda on windows ? I suppose there must be a solution.

Thanks, Marco

like image 447
crillion Avatar asked Sep 20 '25 15:09

crillion


1 Answers

I ran into the same problem. Here's what solved it for me: 1. pip uninstall scrapy 2. conda uninstall scrapy 3. pip install --force --upgrade scrapy 4. scrapy startproject dingding It works.

like image 68
gallonyin Avatar answered Sep 22 '25 06:09

gallonyin