How to use the aiomysql.OperationalError function in aiomysql

To help you get started, we’ve selected a few aiomysql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aio-libs / aiomysql / tests / test_issues.py View on Github external
def test_issue_35(self):
        conn = self.connections[0]
        c = yield from conn.cursor()
        print("sudo killall -9 mysqld within the next 10 seconds")
        try:
            yield from c.execute("select sleep(10)")
            self.fail()
        except aiomysql.OperationalError as e:
            self.assertEqual(2013, e.args[0])
github aio-libs / aiomysql / tests / test_connection.py View on Github external
def test_connect_timeout(self):
        # All exceptions are caught and raised as operational errors
        with self.assertRaises(aiomysql.OperationalError):
            yield from self.connect(connect_timeout=0.000000000001)
github aio-libs / aiomysql / tests / test_connection.py View on Github external
def test_connection_gone_away(self):
        # test
        # http://dev.mysql.com/doc/refman/5.0/en/gone-away.html
        # http://dev.mysql.com/doc/refman/5.0/en/error-messages-client.html
        # error_cr_server_gone_error
        conn = yield from self.connect()
        cur = yield from conn.cursor()
        yield from cur.execute("SET wait_timeout=1")
        yield from asyncio.sleep(2, loop=self.loop)
        with self.assertRaises(aiomysql.OperationalError) as cm:
            yield from cur.execute("SELECT 1+1")
        # error occures while reading, not writing because of socket buffer.
        # self.assertEqual(cm.exception.args[0], 2006)
        self.assertIn(cm.exception.args[0], (2006, 2013))
        conn.close()
github mailgyc / doudizhu / doudizhu / contrib / db / aio_db.py View on Github external
async def _execute(self, cursor: aiomysql.Cursor, query: str, args, kwargs):
        try:
            return await cursor.execute(query, kwargs or args)
        except aiomysql.OperationalError:
            logging.exception("Error connecting to MySQL on %s", self._db_args['host'])
            await self.close()
            raise
github jettify / aiomysql_replication / aiomysql_replication / binlogstream.py View on Github external
def fetchone(self):
        while True:

            try:
                pkt = yield from self._stream_connection._read_packet()
            except aiomysql.OperationalError as error:
                code, message = error.args
                if code in MYSQL_EXPECTED_ERROR_CODES:
                    self._connected_stream = False
                    continue

            if pkt.is_eof_packet():
                return None

            if not pkt.is_ok_packet():
                continue

            binlog_event = BinLogPacketWrapper(pkt, self.table_map,
                                               self._ctl_connection,
                                               self._use_checksum,
                                               self._allowed_events_in_packet,
                                               self._only_tables,