Skip to content
Discussion options

You must be logged in to vote

Then maybe it's not possible because in psycopg2 database errors are only expected to be raised from C and the attribute is read-only from Python.

In psycopg 3 what you want to do is not a problem:

>>> try: raise psycopg.errors.lookup("40001")()
... except Exception as ex: e = ex

>>> e.sqlstate
'40001'

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@arjenzorgdoc
Comment options

@arjenzorgdoc
Comment options

@dvarrazzo
Comment options

Answer selected by arjenzorgdoc
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