“cryptography is required for sha256_password or caching_sha2_password”

痞子三分冷 提交于 2019-12-18 05:46:07

问题


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()

回答1:


import mysql.connector
def connection():
    conn = mysql.connector.connect(host = "XXXXX",
                  user = 'XXXXX',
                  password = 'XXXXX',
                  database = 'login_page',
                  auth_plugin='mysql_native_password')

    c = conn.cursor()
    return c , conn

Download mysql connector rather than pymysql and try connecting this way. It worked for me, hope it works for u too.




回答2:


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

pip install cryptography



回答3:


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



来源:https://stackoverflow.com/questions/54477829/cryptography-is-required-for-sha256-password-or-caching-sha2-password

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!