python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -


import pyodbc,nltk,array cnxn = pyodbc.connect('driver={mysql odbc 5.1 driver};server=127.0.0.1;port=3306;database=information_schema;user=root; password=1234;option=3;') cursor = cnxn.cursor() cursor.execute("use collegedatabase ;") cursor.execute("select *  sampledata ; ") cnxn.commit() s=[] j=[] x=[] words = [] w = [] sfq = [] pos=[] entry in cursor:         s.append(entry.injury_type),j.append(entry.injury_desc)    nltk.tokenize import punktwordtokenizer nltk.corpus import stopwords tokenizer = punktwordtokenizer() english_stops = set(stopwords.words('english')) in range(0,26): # filter stop words             tokenizer.tokenize(j[i])             w.append([word word in tokenizer.tokenize(j[i]) if word not in english_stops])  in range(0 , 26):#converting tokenzied text ito string              sfq.append(" ".join(w[a]))   replacers import regexpreplacer replacer =  regexpreplacer() in range (0,26):#pos tagging             replacer.replace(sfq[a])             pos.append(tokenizer.tokenize(sfq[a]))                             x.append(nltk.pos_tag(pos[a]))              cursor.executemany("update sampledata set pos = %s srno =%d",(x[a],a)) 

the error is:

 traceback (most recent call last):   file "c:\users\vaibhav\dropbox\due monday\tryingtofixerror.py", line 35, in      cursor.executemany("update sampledata set pos = %s srno =%d",(x[a],a)) programmingerror: ('the sql contains 0 parameter markers, 50 parameters supplied', 'hy000') 

after browsing finding solution the problem thought of replacing last line (line 35)with statement

cursor.executemany((u'update sampledata set pos = %s srno =%d'.encode('utf-8'),(x[a],a))(u'mo-mk25'.encode('utf-8')))  

i not know if progressing in right direction or not going thru many websites , forums got hint may there indentation or comma error not know else can guys please me out new programming stuff , btw error code generated given below don't know it.

 traceback (most recent call last):   file "c:\users\vaibhav\dropbox\due monday\tryingtofixerror.py", line 35, in      cursor.executemany((u'update sampledata set pos = %s srno =%d'.encode('utf-8'), (x[a],a)) (u'mo-mk25'.encode('utf-8'))) typeerror: 'tuple' object not callable 

the method executemany(sql, seq_of_parameters) executes same sql statement multiple times set of parameters. therefore, second argument, seq_of_parameters, must sequence of parameter tuples, not single parameter tuple:

cursor.executemany("update sampledata set pos = ? srno = ?", [(x[a], a)]) 

if pass 1 tuple, cursor assume first item, x[a], tuple of parameters. guess string of 50 characters , gets interpreted sequence of 50 parameters, whereas sql string expects 2.

furthermore, notice used ? placeholder symbol instead of %s, since latter seems unsupported pyodbc, reported expected 0 parameters.

in case, might want use execute() method in loop, since want run statement once per iteration:

cursor.execute("update sampledata set pos = ? srno = ?", (x[a], a)) 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -