mysql - 我收到一个错误 SQL 语句中没有使用所有参数
问题描述
下午好,由于某种原因,我收到一个错误 mysql.connector.errors.ProgrammingError:并非所有参数都在 SQL 语句中使用,我检查了所有 %s,它们都显示为 7 以及sql,我敢肯定不是很多,但是如果有人可以看一下,那就太好了
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.")
解决方案
推荐阅读
- apache-spark - Apache Spark 2.3.1 与 HDP 3.0 中的 Hadoop 3.0 的兼容性
- ibm-cloud - IBM Watson Discovery 能否被 IBM Watson Explorer 替代以进行自然语言分析
- javascript - 如何将以下 es-lint 警告 - 警告解决为“预期返回值”?
- python - PyQT:关于菜单栏中的按钮
- apache - 为子域启用 https
- ios - ViewController 根据具体记法推送到next
- reactjs - Reactjs:ReactTable css 不使用 js 文件中的导入加载 css
- parsing - 代码编译过程中需要什么符号表和AST?
- ios - epubjs-rn - 在 iOS 中突出显示文本
- java - Volley GET & Post JSONObject 请求到 TextView 中的 API 视图