|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
各位大佬好,本人在使用python将csv文件读取到sqlite3数据库中已经建好的表的时候,出现了这个错误:sqlite3.OperationalError: near "to": syntax error,想询问是什么原因,
随贴截取部分csv文件的信息如下
Time Source Destination Protocol Length Source Port Destination Port Info
0 192.168.1.20 192.168.1.50 TCP 60 56790 44818 56790 > 44818 [ACK] Seq=1 Ack=1 Win=7922 Len=0
0 192.168.1.50 192.168.1.40 CIP 116 44818 55872 Success: Service (0x4c)
0.000135 192.168.1.40 192.168.1.50 TCP 60 55872 44818 55872 > 44818 [ACK] Seq=1 Ack=63 Win=8130 Len=0
0.000186 192.168.1.20 192.168.1.30 CIP 116 56784 44818 'HMI_LIT301' - Service (0x4c)
0.000291 192.168.1.20 192.168.1.30 CIP 116 56784 44818 'HMI_FIT301' - Service (0x4c)
0.000291 192.168.1.30 192.168.1.20 TCP 60 44818 56784 44818 > 56784 [ACK] Seq=1 Ack=63 Win=8130 Len=0
0.000292 192.168.1.20 192.168.1.30 CIP 116 56784 44818 'HMI_MV301' - Service (0x4c)
0.000396 192.168.1.30 192.168.1.20 TCP 60 44818 56784 44818 > 56784 [ACK] Seq=1 Ack=125 Win=8068 Len=0
0.000396 192.168.1.60 192.168.1.20 CIP I/O 86 Connection: ID=0x00F7464A, SEQ=0042190992
0.000396 192.168.1.30 192.168.1.20 TCP 60 44818 56784 44818 > 56784 [ACK] Seq=1 Ack=187 Win=8006 Len=0
0.000584 192.168.1.20 192.168.1.30 CIP 110 44818 56706 Success: Service (0x4c)
0.000667 192.168.1.30 192.168.1.20 TCP 60 56706 44818 56706 > 44818 [ACK] Seq=1 Ack=57 Win=8136 Len=0
0.00123 192.168.1.10 192.168.1.60 CIP 128 64520 44818 'HMI_PLANT_AUTO' - Service (0x4d)
0.001341 192.168.1.60 192.168.1.10 TCP 60 44818 64520 44818 > 64520 [ACK] Seq=1 Ack=75 Win=8118 Len=0
0.001342 192.168.1.10 192.168.1.20 CIP 124 64512 44818 'HMI_P2_PERMISSIVE' - Service (0x4c)
0.001434 192.168.1.10 239.192.2.63 CIP I/O 98 Connection: ID=0x00708000, SEQ=0008698356
以下是我的代码
import sqlite3
import csv
#数据库连接,建表
conn = sqlite3.connect('networkInfo.db')
cs = conn.cursor()
# cs.execute('''create table netInfo(
# Time,
# Source text,
# Destination text,
# Protocol text,
# Length integer,
# Source_Port text,
# Destination_port text,
# Info text
# )''')
with open('netInfo.csv') as f:
reader = csv.reader(f)
for row in reader:
#跳过第一行表头部分
if row[1] == 'Source':
continue
#print(row[1])
cs.execute(f'insert to netInfo values("{row[0]}","{row[1]}","{row[2]}","{row[3]}","{row[4]}","{row[5]}","{row[6]}","{row[7]}")')
conn.commit()
conn.close()
|
|