Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Case Studies In Business Data Bases

Authors: James Bradley

1st Edition

0030141346, 978-0030141348

More Books

Students also viewed these Databases questions

Question

Identify the main sources of stress and how it affects health.

Answered: 1 week ago