gpt4 book ai didi

python - pymssql连接不返回数据,只打印列名?

转载 作者:行者123 更新时间:2023-12-01 03:24:18 27 4
gpt4 key购买 nike

我正在尝试从服务器获取数据,因此我尝试如下

#!/usr/bin/python
import pymssql
conn = pymssql.connect(host='xxxx', user='xxx', password='xxx', database='xxx')


cursor = conn.cursor()
x2 = 'select * from result where url like\'%get content%\''
cursor.execute(x2)
data = cursor.fetchall()
field_names = [i[0] for i in cursor.description]
print field_names
print data

当我运行这个程序时,它只给出列名称,data 变量为空。我不知道是什么原因。我该如何修复它?

我在 Windows 中运行相同的脚本没有问题。但是当我在 Ubuntu 14.04 中执行脚本时,data 变量为空。

最佳答案

这是 Ubuntu 上 PyMSSQL 1.0.x 的一个已知错误。请参阅No data returned from MSSQL server 。解决方案是将其升级到版本 >= 2.0.1

Due to an issue with PyMSSQL 1.0.x and the version of FreeTDX in the repositories, PyMSSQL no longer returns any information from MSSQL database queries. This means you cannot use fetchone() or fetchall() or similar methods to get data back from a database query.


Thomas Ward (teward) wrote on 2016-06-05:

This is due to an incompatibility between freetdx and PyMSSQL 1.0.x.

Workaround is to remove the python-pymssql package, and run pip
install pymssql
or easy_install --upgrade pymssql or similar, to get the most up to date pymssql version, greater than or equal to 2.0.1.

ALso confirmed this issue on Xenial and Yakkety, as well as Trusty.

关于python - pymssql连接不返回数据,只打印列名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41568984/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com