每次运行此查询时都会出现此错误我正在尝试将csv导入mysql这是我的csv文件
2880,H3KZV,2014/06/24 09:34:28,2014/06/25 09:34:28,1280
2880,R9UZB,2014/06/24 10:34:05,2014/06/24 16:34:05,1340
我在票价上得到这个错误。(1280,1340)#我已经删除了大部分代码
这是我的疑问:
for row in reader:
print row
try:
(location_id, vrm, start_datetime,end_datetime) = [x.decode('utf-8-sig') for x in row]
except:
print "Error with row: " % row
tmp = start_datetime.split(" ")
start_date = tmp[0]
tmp = end_datetime.split(" ")
end_date = tmp[0]
tmp = start_date.split('/')
tmp = end_date.split('/')
SesionCost = ticket_price /100
iso_date = "%s-%s-%s" % (tmp[0], tmp[1], tmp[2])
entryDatetime = "%s 00:00:00 " % iso_date
expiryDatetime = "%s 23:59:59" % iso_date
sql_local = """INSERT INTO customer_1.pay_and_display
(plate, machine_id, ticket_datetime, expiry_datetime, ticket_name, ticket_price)
VALUES ("%s", "%s", "%s", "%s", "%s", "%s") """ % (vrm, location_id, entryDatetime, expiryDatetime, "RINGOtest", 0)
print sql_local
cursor.execute(sql_local)
curl = pycurl.Curl()
body = Body()
payload = [("fn", "addWhitelistEntryValue"),
("firstname", "WL"),
("startDate", start_date.encode('ascii', 'ignore')),
("startTime", "00:00:00"),
("endDate", end_date.encode('ascii', 'ignore')),
("endTime", "23:59:59"),
("vrm", vrm.encode('ascii', 'ignore')),
("locId", location_id.encode('ascii', 'ignore')),
("ticket_price",ticket_price.encode('ascii','ignore'))
]
答案 0 :(得分:1)
ticket_price = float (ticket_price)/100 ... ("ticket_price",ticket_price.encode('ascii','ignore' ))
您认为这究竟是如何运作的?
答案 1 :(得分:0)
SessionCost = float(ticket_price)/ 100.0
iso_date = "%s-%s-%s" % (tmp[0], tmp[1], tmp[2])
entryDatetime = "%s %s " % (iso_date, start_time)
expiryDatetime = "%s %s " % (iso_date, end_time)
sql_local = """INSERT INTO customer_1.pay_and_display
(plate, machine_id, ticket_datetime, expiry_datetime, ticket_name, ticket_price)
VALUES ("%s", "%s", "%s", "%s", "%s", "%s") """ % (vrm, location_id, entryDatetime, expiryDatetime, "RINGOtest",SessionCost)
print sql_local
cursor.execute(sql_local)