幫助大家!我在將數(shù)據(jù)插入 MySQL 數(shù)據(jù)庫時遇到這個問題。我不斷收到此錯誤連接到 MySQL 1264 (22003) 時出錯:第 1 行的“Encours”列的值超出范圍 MySQL 連接已關(guān)閉我正在執(zhí)行這段 python 代碼。我正在做的是抓取網(wǎng)頁而不是格式化它以將其插入數(shù)據(jù)庫 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")
MySQL 1264 (22003):列的值超出范圍
函數(shù)式編程
2023-07-18 13:29:29