Reputation: 5927
I'm trying to fetch the data from server so I tried as follow
#!/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
When I run this program it only give the column name, data
variable is empty. I don't know what is the reason. How can I fix it?
I'm running the same script in windows there is no problem. But when I execute the script in Ubuntu 14.04
the data
variable is empty.
Upvotes: 2
Views: 1173
Reputation: 6103
This is a known bug of PyMSSQL 1.0.x
on Ubuntu. See No data returned from MSSQL server. Solution is to upgrade it to version >= 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
oreasy_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.
Upvotes: 4