import pymssql
import json
def conn():
connect = pymssql.connect('192.168.28.38:1433', 'root', '123456', 'test')
if connect:
#print("sucessful")
cur = connect.cursor(as_dict=True) # 若as_dict为False 返回的是一个列表,而不是字典。
sql = "select * from tb_name "
cur.execute(sql)
ret = cur.fetchall() # ret 中包含datetime.datetime(2018, 10, 30, 14, 9, 0)
connect.close()
ret_json = json.dumps(ret, default=str)
return ret_json
if __name__ == '__main__':
conn = conn()
#print(type(conn))
print(conn)
解决办法:datetime.datetime(2018, 10, 30, 14, 9, 0, 669000, tzinfo=tzlocal()) is not JSON serializable
发表评论
317 views