Mysql 我得到一个错误不是所有参数都用在SQL语句中
下午好,由于某种原因,我得到一个错误mysql.connector.errors.ProgrammingError:SQL语句中没有使用所有参数, 我已经检查了所有的%s,它们都显示为7以及sql中的所有项目,我确信不多,但如果有人可以看一下,那就太好了Mysql 我得到一个错误不是所有参数都用在SQL语句中,mysql,python-3.x,Mysql,Python 3.x,下午好,由于某种原因,我得到一个错误mysql.connector.errors.ProgrammingError:SQL语句中没有使用所有参数, 我已经检查了所有的%s,它们都显示为7以及sql中的所有项目,我确信不多,但如果有人可以看一下,那就太好了 from requests_html import HTMLSession import mysql.connector mydb = mysql.connector.connect( host="localhost", user="
from requests_html import HTMLSession
import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="*****",
database="flightdata"
)
mycursor = mydb.cursor()
# create an HTML Session object
session = HTMLSession()
# Use the object above to connect to needed webpage
resp = session.get("https://www.adelaideairport.com.au/flight-information/flight-search/?flt_no=&carrier=All&city=&dte=Current&leg=Departures")
# Run JavaScript code on webpage
resp.html.render()
airline_spans = resp.html.find('.SearchResultFlightListRow')
print (airline_spans)
airline_list = [span.text.split('\n') for span in airline_spans]
for flight in airline_list:
if len(flight) == 7:
flightno, From, to, scheduled, estimated, gate, status = flight
print ("This is a " + estimated)
if estimated == "":
print (" currently no dely ")
print ("This is a " + estimated)
estimated = 'IDEL'
print (f'Flight no {flightno} from {From} to {to} is scheduled to depart at {scheduled} from gate {gate} and flight status is {status}')
elif len(flight) == 6:
flightno, From, to, scheduled, estimated, gate = flight
status = 'IDEL'
print ("This is a " + estimated)
if estimated == "":
print (" currently no dely ")
print ("This is a " + estimated)
estimated = 'IDEL'
print (f'Flight no {flightno} from {From} to {to} is scheduled to depart at {scheduled} from gate {gate} ')
elif len(flight) == 5:
flightno, From, to, scheduled, estimated = flight
gate = 'IDEL'
status = 'IDEL'
print ("This is a " + estimated)
if estimated == "":
print (" currently no dely ")
print ("This is a " + estimated)
estimated = 'IDEL'
print (f'Flight no {flightno} from {From} to {to} is scheduled to depart at {scheduled} from gate ')
sql = "INSERT INTO flightinfo (origin, airline, destinations, flightNumbers, scheduledTime, estimatedTime, status) VALUES (%s, %s, %s, %s, %s, %s, %s)"
val = (From, to, flightno, scheduled, estimated, status, gate)
#data.append(val)
# doing a batch insert
mycursor.executemany(sql, val)
mydb.commit()
print(mycursor.rowcount, "was inserted.")
executemany
需要一个元组列表,但您只为一次执行提供一个元组。我不认为你想执行很多,是吗?我不确定mate在这方面是否仍然是n00b:)我想做的就是将数据放入数据库:)尝试将executemany
更改为execute
…好的,但当我需要所有行时,它只插入了一行