我在mysql workbench 5.7中創建了5個表,我將從APIgraph查詢中爲給定的Facebook頁面提取數據。Python中的SQL%語句返回錯誤
然而,當我運行的代碼,它拋出一個錯誤:
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"]
你可以通過你的''json_pageiddata''變量 –
嗨,我更新了我的問題與您的需求! –