帮助大家!我在将数据插入 MySQL 数据库时遇到这个问题。我不断收到此错误连接到 MySQL 1264 (22003) 时出错:第 1 行的“Encours”列的值超出范围 MySQL 连接已关闭我正在执行这段 python 代码。我正在做的是抓取网页而不是格式化它以将其插入数据库 rows = []# loop over resultsfor result in results:# find all columns per result data = result.find_all('td')# check that columns have data if len(data) == 0: continue # if len(data)!=0 execute the rest ISIN = data[1].getText() Libelle = data[2].getText() Nominal = normalize('NFKD',data[4].getText()).replace(' ','') Encours = normalize('NFKD',data[5].getText()).replace(' ','') DerniereEcheance = data[6].getText() InterestRate = data[7].getText().replace('%','').replace(',','.') nom = int(Nominal) enc=Encours.strip() date_time_obj = datetime.datetime.strptime(str(DerniereEcheance).strip(), '%d/%m/%Y').strftime('%Y-%m-%d') intRate = float(InterestRate) rows.append([ISIN,Libelle,nom,enc,date_time_obj,intRate])print(rows)driver.quit()"""connection"""try: connection = mysql.connector.connect(host='localhost', database='biatfinancialdata', user='root', password='root') if connection.is_connected(): cursor = connection.cursor() for row in rows: sql = "INSERT INTO t_bta (EffectiveDate, ISIN, Libelle, Nominal, Encours,DerniereEcheance,InterestRate) VALUES (%s, %s, %s, %s, %s, %s, %s)" val =(datetime.date.today(),row[0],row[1],row[2],row[3],row[4],row[5]) cursor.execute(sql,val) print('im here') connection.commit()except Error as e: print("Error while connecting to MySQL", e)finally: if (connection.is_connected()): cursor.close() connection.close() print("MySQL connection is closed")
1 回答
智慧大石
TA贡献1946条经验 获得超3个赞
当尝试放置的值大于列的变量类型规范所允许的值时,通常会发生此错误。您没有提到女巫列是错误的根源,但我们可以假设它是 varchar 字段类型,并且显然,您超出了分配的长度。检查输入值和表列规格。每个字段类型都会发生此错误。
添加回答
举报
0/150
提交
取消