我试图理解当我设置 python 代码在 VM 服务器上运行时开始出现的以下错误,该服务器在我的桌面上安装了 3.9.5 而不是 3.8.5。不确定这是否重要,但这可能是部分原因。
错误
C:\ProgramData\Miniconda3\lib\site-packages\pandas\io\sql.py:758: UserWarning: pandas only support SQLAlchemy connectable(engine/connection) or
database string URI or sqlite3 DBAPI2 connection
other DBAPI2 objects are not tested, please consider using SQLAlchemy
warnings.warn(
Run Code Online (Sandbox Code Playgroud)
这是一个相当简单的 .py 文件,该文件导入 pyodbc 和 sqlalchemy fwiw。产生警告的 sql 调用的相当通用/简单的版本是:
myserver_string = "xxxxxxxxx,nnnn"
db_string = "xxxxxx"
cnxn = "Driver={ODBC Driver 17 for SQL Server};Server=tcp:"+myserver_string+";Database="+db_string +";TrustServerCertificate=no;Connection Timeout=600;Authentication=ActiveDirectoryIntegrated;"
def readAnyTable(tablename, date):
conn = pyodbc.connect(cnxn)
query_result = pd.read_sql_query(
'''
SELECT *
FROM [{0}].[dbo].[{1}]
where Asof >= '{2}'
'''.format(db_string,tablename,date,), conn) …Run Code Online (Sandbox Code Playgroud) 我正在尝试启动与 Azure SQL 数据库的连接。出于安全原因,我无法硬编码用户名和密码,我需要从配置文件中的字典中获取它,并以这种方式将其放入连接 URL 中。
当我尝试这样做并在 Jupyter 笔记本中运行它时, 并{key[value]}没有被配置文件中引用的内容替换。
如果我使用格式化字符串,我会得到一个KeyError. 如果我不使用格式化字符串,它只会打印{variablename}字面意思。