我是python新手,如果我的问题和我的英语听起来一点都不对,我很抱歉。 我一直在尝试将我的抓取输出集成到mysql,但不幸的是我被卡住了。你们这些好人能帮我吗
KeyError回溯(最近一次呼叫最后一次) 在里面 9数据=csv.DictReader(scrapeddata) 10对于数据中的行: ---&燃气轮机;11 sql=“插入emas(tanggal、terakhir、pembukaan、tertinggi、Terendeah、vol、perubahan%)值(“%s”、“s”、“s”、“s”、“s”、“s”、“s”、“s”、“s”)””)%(str(row[“tanggal”])、str(row[“terakhir”]、str(row[“pembukaan”]、str(row[“tertinggi”]、str(row[“vol”]、str(row[“perubahan%”)) 12打印(sql) 13当前执行(sql)
KeyError:'tanggal'*
这是我的密码
import csv
import pymysql
#Connecting to MySQL in Windows
conn = pymysql.connect(host="127.0.0.1", port = 3306, user = "root", passwd = '', database = "mysql",
charset = "utf8")
cur = conn.cursor()
cur.execute("USE historis")
print(cur)
print(conn)
with open(r'C:\Users\shulhan\output_emas.csv') as scrapeddata:
data = csv.DictReader(scrapeddata)
for row in data:
sql = "INSERT INTO emas ( tanggal, terakhir, pembukaan, tertinggi, terendah, vol, perubahan%)
VALUES ('%s','%s','%s','%s','%s','%s','%s')"
%(str(row["tanggal"]),str(row["terakhir"]),str(row["pembukaan"]),str(row["tertinggi"]),str(row["terendah"]),str(row["vol"]),str(row["perubahan%"]))
print(sql)
cur.execute(sql)
conn.commit()
我认为您的连接设置应该如下所示:
您可以在此处找到更多信息: https://pymysql.readthedocs.io/en/latest/user/examples.html
相关问题 更多 >
编程相关推荐