当前位置: 首页>>代码示例>>Python>>正文


Python pymysql.InternalError方法代码示例

本文整理汇总了Python中pymysql.InternalError方法的典型用法代码示例。如果您正苦于以下问题:Python pymysql.InternalError方法的具体用法?Python pymysql.InternalError怎么用?Python pymysql.InternalError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pymysql的用法示例。


在下文中一共展示了pymysql.InternalError方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: process_item

# 需要导入模块: import pymysql [as 别名]
# 或者: from pymysql import InternalError [as 别名]
def process_item(self, item, spider):
        if spider.name in ['RssCrawler', 'GdeltCrawler']:
            # Search the CurrentVersion table for a version of the article
            try:
                self.cursor.execute(self.compare_versions, (item['url'],))
            except (pymysql.err.OperationalError, pymysql.ProgrammingError, pymysql.InternalError,
                    pymysql.IntegrityError, TypeError) as error:
                self.log.error("Something went wrong in rss query: %s", error)

            # Save the result of the query. Must be done before the add,
            #   otherwise the result will be overwritten in the buffer
            old_version = self.cursor.fetchone()

            if old_version is not None and (datetime.datetime.strptime(
                    item['download_date'], "%y-%m-%d %H:%M:%S") -
                                            old_version[3]) \
                    < datetime.timedelta(hours=self.delta_time):
                # Compare the two download dates. index 3 of old_version
                # corresponds to the download_date attribute in the DB
                raise DropItem("Article in DB too recent. Not saving.")

        return item 
开发者ID:fhamborg,项目名称:news-please,代码行数:24,代码来源:pipelines.py

示例2: fetch_all

# 需要导入模块: import pymysql [as 别名]
# 或者: from pymysql import InternalError [as 别名]
def fetch_all(sql_content, host, port, user, password, db_in):
    """
    封装mysql连接和获取结果集方法
    :param sql_content:
    :param host:
    :param port:
    :param user:
    :param password:
    :param db_in:
    :return:
    """
    result = None
    conn = None
    cur = None
    sql_content = sql_content.encode('utf-8').decode('utf-8')

    try:
        conn = pymysql.connect(
            host=host,
            user=user,
            password=password,
            db=db_in,
            port=port,
            charset='utf8mb4'
        )
        cur = conn.cursor()
        cur.execute(sql_content)
        result = cur.fetchall()
    except pymysql.InternalError as e:
        print("Mysql Error %d: %s" % (e.args[0], e.args[1]))
    finally:
        if cur is not None:
            cur.close()
        if conn is not None:
            conn.close()

    return result 
开发者ID:Tianny,项目名称:incepiton-mysql,代码行数:39,代码来源:inception.py

示例3: connect

# 需要导入模块: import pymysql [as 别名]
# 或者: from pymysql import InternalError [as 别名]
def connect(self):
        self.initConnection()

        try:
            self.connector = pymysql.connect(host=self.hostname, user=self.user, passwd=self.password, db=self.db, port=self.port, connect_timeout=conf.timeout, use_unicode=True)
        except (pymysql.OperationalError, pymysql.InternalError), msg:
            raise SqlmapConnectionException(msg[1]) 
开发者ID:krintoxi,项目名称:NoobSec-Toolkit,代码行数:9,代码来源:connector.py

示例4: convert_exceptions

# 需要导入模块: import pymysql [as 别名]
# 或者: from pymysql import InternalError [as 别名]
def convert_exceptions(msg: str) -> Iterator:
    """Convert internal mysql exceptions to our InvalidDatabaseError"""
    from pymysql import OperationalError, InternalError, ProgrammingError
    try:
        yield
    except (OperationalError, InternalError, ProgrammingError) as exc:
        raise exceptions.InvalidDatabaseError(msg) from exc 
开发者ID:DHI-GRAS,项目名称:terracotta,代码行数:9,代码来源:mysql.py

示例5: reset_mysql

# 需要导入模块: import pymysql [as 别名]
# 或者: from pymysql import InternalError [as 别名]
def reset_mysql(self):
        """
        Resets the MySQL database.
        """

        confirm = self.no_confirm

        print("""
Cleanup MySQL database:
    This will truncate all tables and reset the whole database.
""")

        if not confirm:
            confirm = 'yes' in builtins.input(
                """
    Do you really want to do this? Write 'yes' to confirm: {yes}"""
                    .format(yes='yes' if confirm else ''))

        if not confirm:
            print("Did not type yes. Thus aborting.")
            return

        print("Resetting database...")

        try:
            # initialize DB connection
            self.conn = pymysql.connect(host=self.mysql["host"],
                                        port=self.mysql["port"],
                                        db=self.mysql["db"],
                                        user=self.mysql["username"],
                                        passwd=self.mysql["password"])
            self.cursor = self.conn.cursor()

            self.cursor.execute("TRUNCATE TABLE CurrentVersions")
            self.cursor.execute("TRUNCATE TABLE ArchiveVersions")
            self.conn.close()
        except (pymysql.err.OperationalError, pymysql.ProgrammingError, pymysql.InternalError,
                pymysql.IntegrityError, TypeError) as error:
            self.log.error("Database reset error: %s", error) 
开发者ID:fhamborg,项目名称:news-please,代码行数:41,代码来源:__main__.py

示例6: connect

# 需要导入模块: import pymysql [as 别名]
# 或者: from pymysql import InternalError [as 别名]
def connect(self):
        self.initConnection()

        try:
            self.connector = pymysql.connect(host=self.hostname, user=self.user, passwd=self.password, db=self.db, port=self.port, connect_timeout=conf.timeout, use_unicode=True)
        except (pymysql.OperationalError, pymysql.InternalError, pymysql.ProgrammingError, struct.error), msg:
            raise SqlmapConnectionException(getSafeExString(msg)) 
开发者ID:sabri-zaki,项目名称:EasY_HaCk,代码行数:9,代码来源:connector.py


注:本文中的pymysql.InternalError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。