我正在尝试连接到 SQLAlchemy 中的引擎,但出现以下错误:
DBAPIError: (pyodbc.Error) ('HY000', '[HY000] [Oracle][ODBC][Ora]ORA-00923: FROM keyword not found where expected\n\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x13\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 (923) (SQLExecDirectW)')
[SQL: SELECT schema_name()]
(Background on this error at: https://sqlalche.me/e/20/dbapi)
我尝试了以下内容,使用字符串用户 ID (
uid
)、密码 (pwd
) 和 DSN (dsn
):
from sqlalchemy import create_engine
import urllib
params = (
f"DSN={dsn};"
f"UID={uid};"
f"PWD={pwd}"
)
params = urllib.parse.quote_plus(params)
con = create_engine(f"mssql+pyodbc:///?odbc_connect={params}").connect()
我也尝试提供直接字符串
f"mssql+pyodbc://{uid}:{pwd}@{dsn}"
给出了同样的错误。
我假设我创建 url 的方式出了问题。
如果有帮助,我已经通过执行以下操作使用 pyodbc 成功建立了连接:
con = pyodbc.connect(
f"DSN={dsn};"
f"UID={uid};"
f"PWD={pwd}"
)