Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"cryptography is required for sha256_password or caching_sha2_password"

Good day. Hope your all are well. Can someone help me with fix this?

I'm new to the MySQL environment. I'm trying to connect to MySQL Database remotely. I used the following python code and got this error.

Print(e) = "cryptography is required for sha256_password or 
             caching_sha2_password"

And have no idea how to solve the error.

import pymysql as db

HOST = "XXXXX.XXX.XX”
PORT = XXXX
USER = "my_username"
PASSWORD = "my_password”
DB = "db_name"

try:
    connection = db.Connection(host=HOST, port=PORT,user=USER,                 
    passwd=PASSWORD, db=DB)

    dbhandler = connection.cursor()
    dbhandler.execute("SELECT * from table_name")
    result = dbhandler.fetchall()
    for item in result:
        print (DB)
 except Exception as e:
    print(e)

finally:
    connection.close()
like image 695
Tania Rheeder Avatar asked Feb 01 '19 10:02

Tania Rheeder


People also ask

What does sha256_password with caching_sha2_password mean?

"This report means that sha256_password with caching_sha2_password These two encryption algorithms need to use cryptography. Although the meaning is clear, you may not know how to solve it. Try running pip install cryptography on you cmd or terminal.

How do I use RSA password encryption with sha256_password?

To use RSA password encryption with sha256_password, the client and server both must be compiled using OpenSSL, not just one of them. Assuming that MySQL has been compiled using OpenSSL, use the following procedure to enable use of an RSA key pair for password exchange during the client connection process:

Where can I find information about the caching SHA-2 Authentication plugin?

For information about the caching plugin, see Section 6.4.1.2, “Caching SHA-2 Pluggable Authentication” . In MySQL 8.0, caching_sha2_password is the default authentication plugin rather than mysql_native_password.

Why is caching_sha2_password the default authentication plugin in MySQL 8?

In MySQL 8.0, caching_sha2_password is the default authentication plugin rather than mysql_native_password. For information about the implications of this change for server operation and compatibility of the server with clients and connectors, see caching_sha2_password as the Preferred Authentication Plugin .


4 Answers

The error message can be made more comprehensive and helpful. In order to fix this "cryptography" package needs to be installed.

pip install cryptography
like image 159
Amit Kumar Avatar answered Oct 19 '22 23:10

Amit Kumar


To use “sha256_password” or “caching_sha2_password” for authenticate, you need to install additional dependency:

$ python3 -m pip install PyMySQL[rsa]

Source: https://pymysql.readthedocs.io/en/latest/user/installation.html

like image 25
gajam Avatar answered Oct 19 '22 21:10

gajam


For what it's worth, I had this problem today using MySQL via SQLAlchemy in Python. It turned out that I was using the wrong password for this account. In other words, if you have this problem, you might want to start by just confirming that you're using the correct password.

FWIW, I am not sure why this generated a cryptography message. Something buggy along the way?

like image 15
Ben Avatar answered Oct 19 '22 21:10

Ben


"This report means that sha256_password with caching_sha2_password These two encryption algorithms need to use cryptography.
Although the meaning is clear, you may not know how to solve it.
Actually, cryptography is a python package, so the solution is simple:"

Try running pip install cryptography on you cmd or terminal.
Here is the source.

like image 7
Carlos S Avatar answered Oct 19 '22 23:10

Carlos S