1

I am receiving "TypeError: bad argument type for built-in operation" error when calling cursor.columns from pyodbc, Traceback the issue to threading.py -> currentThread function...

I have installed my python environment on a new HP Z2 desktop PC running : Win10 enterprise x64 Python 2.7.13 on win32 PyScripter 3.5.1.0 x86

and suddenly received a very strange error while trying to insert data into my database using pyodbc module. My code -

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

The error I receive -

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

This is very strange because it is working perfectly on other old PC I have running the same environment. What do I miss here ? tried re-installing python, pyscripter ...

Daniel Sapir
  • 23
  • 1
  • 4

0 Answers0