【问题标题】:My SQL Python ProgrammingError: 1064 (42000) [closed]Mysql Python ProgrammingError:1064(42000)[关闭]
【发布时间】:2019-10-21 13:59:21
【问题描述】:

我正在尝试使用 scrapy 将抓取的数据存储到 sql 数据库,但出现以下错误:ProgrammingError: 1064 (42000): You have an error in your SQL syntax;检查与您的 MySQL 服务器版本相对应的手册,以在第 7 行的 ')' 附近使用正确的语法

请在下面找到我的 pipelines.py

from datetime import datetime
import mysql.connector
from mysql.connector import errorcode

class LecturesinparisPipeline(object):
    ...
class CleaningPipeline(object):
    ...

class DatabasePipeline(object):

    def __init__(self):
        self.create_connection()
        self.create_table()

    def create_connection(self):
        self.conn = mysql.connector.connect(
            host='localhost',
            user='root',
            passwd='sTUDIO987',
            database='lecturesinparis_db'
        )
        self.curr = self.conn.cursor()

    def create_table(self):
        self.curr.execute("""DROP TABLE IF EXISTS mdl""")
        self.curr.execute("""create table mdl(
                        title text,
                        location text,
                        startdatetime text,
                        lenght text,
                        description text,
                        )""")

    def process_item(self, item, spider):
        self.store_db(item)
        return item

    def store_db(self, item):
        self.curr.execute("""insert into mdl values (%s,%s,%s,%s,%s)""", (
            item['title'][0],
            item['location'][0],
            item['startdatetime'][0],
            item['lenght'][0],
            item['description'][0]
        ))
        self.conn.commit()

【问题讨论】:

  • 请显示完整的回溯,或告诉我们该消息属于哪些查询。
  • 你给我们上课,但你没有展示你实际运行的代码

标签: python mysql sql database scrapy


【解决方案1】:

你昏迷太多了,

改用

def create_table(self):
    self.curr.execute("""DROP TABLE IF EXISTS mdl""")
    self.curr.execute("""create table mdl(
                    title text,
                    location text,
                    startdatetime text,
                    lenght text,
                    description text
                    )""")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-06
    • 2014-11-18
    • 2014-07-05
    • 2018-03-05
    • 1970-01-01
    • 1970-01-01
    • 2020-06-24
    • 2020-11-27
    相关资源
    最近更新 更多