Question: I get this error when running a python script =================== RESTART: C:/Users/Terrie/Desktop/1.py =================== Traceback (most recent call last): File C:/Users/Terrie/Desktop/1.py, line 24, in db_cursor.execute(selectSQL,cycle[0]) File

I get this error when running a python script

=================== RESTART: C:/Users/Terrie/Desktop/1.py =================== Traceback (most recent call last): File "C:/Users/Terrie/Desktop/1.py", line 24, in db_cursor.execute(selectSQL,cycle[0]) File "C:\Users\Terrie\AppData\Local\Programs\Python\Python37\lib\site-packages\mysql\connector\cursor_cext.py", line 248, in execute prepared = self._cnx.prepare_for_mysql(params) File "C:\Users\Terrie\AppData\Local\Programs\Python\Python37\lib\site-packages\mysql\connector\connection_cext.py", line 535, in prepare_for_mysql raise ValueError("Could not process parameters") ValueError: Could not process parameters

this is the python script:

import mysql.connector db_con = mysql.connector.connect( # TODO: change the host,user,passwd as per yours host="localhost", user="root", passwd="Tessylou=12", database="accidents", ) # getting the cursor db_cursor = db_con.cursor()

db_cursor.execute('SELECT vtype FROM vehicle_type WHERE vtype LIKE "%otorcycle%";') cycleList = db_cursor.fetchall() selectSQL = (''' select t.vtype, a.accident_severity from accidents_2016 as a join vehicles_2016 as v on a.accident_index = v.accident_index join vehicle_type as t on v.vehicle_type = t.vcode where t.vtype like %s order by a.accident_severity;''') insertSQL = ('''INSERT INTO accident_medians VALUES (%s, %s);''')

for cycle in cycleList: db_cursor.execute(selectSQL,cycle[0]) accidents = cursor.fetchall() quotient, remainder = divmod(len(accidents),2) if remainder: med_sev = accidents[quotient][1] else: med_sev = (accidents[quotient][1] + accidents[quotient+2][1])/2 print('Finding median for',cycle[0]) cursor.execute(insertSQL,(cycle[0],med_sev)) myConnection.commit() myConnection.close() It seems to be the where t.vtype like %s statement. The %s maybe the problem but I am not sure what else to use.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!