Menu

(Solved) : Get Error Running Python Script Restart C Users Terrie Desktop 1py Traceback Recent Call L Q34234765 . . .

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<module>
db_cursor.execute(selectSQL,cycle[0])
File”C:UsersTerrieAppDataLocalProgramsPythonPython37libsite-packagesmysqlconnectorcursor_cext.py”,line 248, in execute
prepared = self._cnx.prepare_for_mysql(params)
File”C:UsersTerrieAppDataLocalProgramsPythonPython37libsite-packagesmysqlconnectorconnection_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 vtypeLIKE “%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 maybethe problem but I am not sure what else to use.

Expert Answer


Answer to Get Error Running Python Script Restart C Users Terrie Desktop 1py Traceback Recent Call L Q34234765 . . .

OR