Skip to content

how to import aiomysql errors #717

Answered by Nothing4You
xrokz asked this question in Q&A
Discussion options

You must be logged in to vote

Hi,

unfortunately this question is quite old and therefore probably not relevant anymore.
aiomysql generally raises the same error types as PyMySQL (where applicable).
for convenience we also provide the PyMySQL error types in the aiomysql package.
in case of an incorrect table name foo this raises pymysql.err.ProgrammingError: (1146, "Table 'mysql.foo' doesn't exist").
the error code will be available in e.args[0].

example:

from pymysql.constants import ER

try:
    await cursor.execute("select 1 from foo")
except aiomysql.ProgrammingError as e:
    if e.args[0] == ER.NO_SUCH_TABLE: # 1146
        print("table doesn't exist")
    else:
        raise e

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Nothing4You
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #381 on January 30, 2022 09:42.