gpt4 book ai didi

mysql - python 中的 SQL % 语句返回错误

转载 作者:行者123 更新时间:2023-11-29 19:45:55 25 4
gpt4 key购买 nike

我在 mysql workbench 5.7 中创建了 5 个表,在其中我将从给定 Facebook 页面的 APIgraph 查询中提取数据。

但是,当我运行代码时,它会抛出错误:

ProgrammingError: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s, %s)' at line 1

这是我认为包含错误的代码部分:

#create connection to db
connection = connect_db()
cursor = connection.cursor()

#SQL request for inserting the date of the page into the database
insert_page = ("INSERT INTO page"
"(fb_id, name)"
"VALUES (%s, %s)")

insert_posts = ("INSERT INTO posts "
"(page_id, fb_post_id, message, time_created)"
"VALUES (%s, %s, %s, %s)")

最后我把数据放在代码的末尾:

cursor.execute(insert_page, json_pageiddata)

有什么想法吗?感谢您的帮助

编辑:这是我的 json_pageiddtata 变量,通过 APIgraph 的 URL 查询获得:

    pageid_url = create_pageid_url(current_page, APP_ID, APP_SECRET)
json_pageiddata = render_to_json(pageid_url)
print json_pageiddata["name"], json_pageiddata["id"]

最佳答案

如果您使用数据作为字典,您需要指定索引名称,请尝试使用%(name)s

关于mysql - python 中的 SQL % 语句返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40979763/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com