当我运行以下代码片段时,我得到错误sqlalchemy.exc.NotSupportedError: (mysql.connector.errors.NotSupportedError) Authentication plugin https://stackoverflow.com/questions/57459623/does-sqlalchemy-support-caching-sha2-password-if-yes-then-how?noredirect=1&lq=1'caching_sha2_password' is not supported
:
import sqlalchemy
from sqlalchemy.ext.declarative import declarative_base
# Define the MySQL engine using MySQL Connector/Python
engine = sqlalchemy.create_engine(
'mysql+mysqlconnector://pyuser:Py@pp4Demo@localhost:3306/sqlalchemy', connect_args={'auth_plugin':'mysql_native_password'}, echo=True)
# Define and create the table
Base = declarative_base()
class User(Base):
__tablename__ = 'user'
id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
name = sqlalchemy.Column(sqlalchemy.String(length=50))
fullname = sqlalchemy.Column(sqlalchemy.String(length=50))
nickname = sqlalchemy.Column(sqlalchemy.String(length=50))
def __repr__(self):
return "<User(name='{0}', full name='{1}', nick name='{2}')>".format(
self.name, self.fullname, self.nickname)
# Create a session
Session = sqlalchemy.orm.sessionmaker()
Session.configure(bind=engine)
session = Session()
Base.metadata.drop_all(bind=engine)
Base.metadata.create_all(bind=engine)
字符串
有此代码片段的脚本一直工作到一段时间前.我最近需要在另一个脚本中import mysql.connector
并执行pip install mysql-connector-python-rf
.然后,我已经开始得到这个错误与此脚本.我已经看了其他线程讨论这个错误,但无法解决在我的情况下的错误.例如.,我添加connect_args={'auth_plugin':'mysql_native_password'}
后阅读this,但仍然得到相同的错误.
1条答案
按热度按时间3okqufwl1#
我有同样的问题,然后发现这是因为我安装了错误的软件包
pip install mysql-connector-python
然后导入为import mysql.connector
有了这个命令,