小编Jos*_*tel的帖子

将 pyodbc Connection 对象与 pandas 一起使用时收到警告

我试图理解当我设置 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)

sql-server pyodbc python-3.x pandas

76
推荐指数
4
解决办法
14万
查看次数

标签 统计

pandas ×1

pyodbc ×1

python-3.x ×1

sql-server ×1