python - 调用pyodbc游标时出现线程错误
问题描述
从 pyodbc 调用 cursor.columns 时,我收到“TypeError:内置操作的参数类型错误”错误,将问题追溯到 threading.py -> currentThread 函数...
我已经在一台新的 HP Z2 台式电脑上安装了我的 python 环境,运行:Win10 企业 x64 Python 2.7.13 on win32 PyScripter 3.5.1.0 x86
尝试使用 pyodbc 模块将数据插入我的数据库时突然收到一个非常奇怪的错误。我的代码 -
class clsDataBaseWrapper():
def __init__(self,ServerAddress='WIGIG-703\SQLEXPRESS',DataBase='QCT_Python',dBEn=1):
if (dBEn) :
self.DataBase=DataBase
self.cnxn = pyodbc.connect("Driver={SQL Server}"+
"""
;Server={0};
Database={1};
Trusted_Connection=yes;""".format(ServerAddress,DataBase))
self.cursor = self.cnxn.cursor()
else : print "\n*** Be Aware - you are not writing data to the DataBase !!! ***"
def InsertData(self,Table,Data,dBEn):
if (dBEn) :
columns = self.cursor.columns(table=Table, schema='dbo').fetchall()
insertQuery = "insert into {0} values ({1})".format(Table, ','.join('?' * len(columns)))
try :
self.cursor.execute(insertQuery, Data)
self.cnxn.commit()
except Exception,e : print 'could not insert data into DB - ',e
else : pass
我收到的错误 -
C:\Python27\lib\threading.py:1151: RuntimeWarning: tp_compare didn't return -1 or -2 for exception
return _active[_get_ident()]
Traceback (most recent call last):
File "C:\Qpython\IsonM_TC2\Services_IsonM_TC2.py", line 335, in <module>
test.InsertData('PLL_CL_PN_PLL',[],1)
File "C:\Qpython\IsonM_TC2\Services_IsonM_TC2.py", line 87, in InsertData
columns = columns.fetchall()
File "C:\Qpython\IsonM_TC2\Services_IsonM_TC2.py", line 87, in InsertData
columns = columns.fetchall()
File "C:\Python27\lib\bdb.py", line 49, in trace_dispatch
return self.dispatch_line(frame)
File "C:\Python27\lib\bdb.py", line 67, in dispatch_line
self.user_line(frame)
File "<string>", line 126, in user_line
File "C:\Python27\lib\threading.py", line 1151, in currentThread
return _active[_get_ident()]
TypeError: bad argument type for built-in operation
这很奇怪,因为它在我运行相同环境的其他旧 PC 上运行良好。我在这里想念什么?尝试重新安装python,pyscripter ...
解决方案
推荐阅读
- c++ - 分配长度 char* 参数的 std::regex_search 在 VS2017 中不起作用?
- apache-spark - OSError:[Errno 8] 执行格式错误:'/home/ubuntu/spark-2.3.2-bin-hadoop2.7/./bin/spark-submit'
- c# - C#中异步方法的返回类型
- asp.net-core - .Net core Web api 2 - 委托处理程序或中间件
- visual-studio-2015 - Crystal Report - 详细信息部分根据订单号水平递增
- server - ASP.NET Core 部署要求
- ruby-on-rails - 无法通过 capistrano 部署 rails 5 应用程序
- c++ - 如果模板构造函数只有一个泛型参数,为什么我必须要有一个复制构造函数?
- php - Codeigniter - 带循环的多输入
- docker - Docker 镜像文件位置