Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 PyODBC error - second parameter to executemany must be a sequence, iterator, or gener
#1
Hello,

I am trying this to get some values into SQLServer2017. when I try this code it throws pyodbc.ProgrammingError: The second parameter to executemany must be a sequence, iterator, or generator. How can I fix this

Thanks in advance
for key, value in myDict.items():
        for idx,retData in enumerate(value): 
            #everything into dict
            retData["remotecontrol_id"], idx
            retData["device_id"],idx 
            retData["alias"], idx
            retData["groupid"], idx
            retData["online_state"], idx
                        
            
    sqeel = ("""INSERT INTO dbo.devTBLA[remotecontrol_id], [device_id], [alias],[groupid],
    [online_state])) 
    values(%s, %s, %s, %s, %s, %s, %s)""")
    numRows = cursor.executemany(sqeel, retData) #second parameter to executemany must be a    sequence, iterator, or generator.


    connStr.commit()
    cursor.close()
    connStr.close()
Larz60+ wrote Mar-29-2019, 05:23 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

Please use BBCode tags, 2nd notice. Again fixed for you.
Quote
#2
Hello Larx60+
Here is the code, Let me know if what else is needed> Thanks
import requests
from requests.auth import HTTPDigestAuth
import json
from pandas.io.json import json_normalize
import pandas as pd
from pandas import ExcelWriter
import random
import pyodbc
import sqlalchemy
def DBInsertD():
headers = {"content-type": "application/json", "Authorization": "Bearer nnnnn"}
    r = requests.get(url, headers=headers)   
    r3 = r.json() #Convert to JSON
connStr= pyodbc.connect('DRIVER={SQL Server};Server=Servername;Trusted_Connection=True;DATABASE=myDB')
    cursor = connStr.cursor()
    for key, value in r3.items():
        for idx,retData in enumerate(value): 
            #everything into dict
            retData["remotecontrol_id"], idx
            retData["device_id"],idx 
            retData["alias"], idx
            retData["groupid"], idx
            retData["online_state"], idx 
            
                        
            
    sqeel = ("""INSERT INTO dbo.TVDevicesA[remotecontrol_id], [device_id], [alias],[groupid],
    [online_state])) 
    values(%s, %s, %s, %s, %s, %s, %s)""")
    numRows = cursor.executemany(sqeel, x) #pyodbc.ProgrammingError: The second parameter to executemany must be a sequence, iterator, or generator.


    connStr.commit()
    cursor.close()
    connStr.close()
DBInsertD()
Error output
Error:
pyodbc.ProgrammingError: The second parameter to executemany must be a sequence, iterator, or generator. The program '[12832] python.exe' has exited with code -1 (0xffffffff)
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  pyodbc.Error SQLBindParameter pcarra 0 258 Jul-08-2019, 08:22 PM
Last Post: pcarra
  Pyodbc error taxit 1 572 Jun-18-2019, 01:13 AM
Last Post: Larz60+
  looking for a sprcil iterator Skaperen 7 344 Jun-13-2019, 01:40 AM
Last Post: Clunk_Head
  Using VBA to Call a Python script causes error in pyodbc connector pcarra 1 403 Jun-11-2019, 04:14 PM
Last Post: pcarra
  Using executemany to import the data Sandy7771989 1 261 Jun-11-2019, 07:45 AM
Last Post: Sandy7771989
  last pass of for x in iterator: Skaperen 13 756 May-20-2019, 10:05 PM
Last Post: Yoriz
  MySQL executemany - Failed executing the operation; Could not process parameters josh_marchant 1 628 May-16-2019, 04:22 PM
Last Post: woooee
  Split List and Sublist from Pyodbc parthi1705 1 324 May-05-2019, 10:44 AM
Last Post: Larz60+
  Read CSV file into MySQL and use executemany instead of execute bluethundr 1 650 May-04-2019, 07:35 AM
Last Post: MvGulik
  iterator from an iterator Skaperen 3 412 Apr-17-2019, 06:56 AM
Last Post: Skaperen

Forum Jump:


Users browsing this thread: 1 Guest(s)