NotSupportedError contains a str, not a cx_Oracle._Error object · Issue #51 · oracle/python-cx_Oracle (original) (raw)
When I follow the docs' guidance on exception handling, a NotSupportedError contains a string, not the expected cx_Oracle._Error object. Below is a short script that reproduces the issue. I'm using a dict as an example variable, but any unsupported variable type will throw this error.
from future import print_function import cx_Oracle
connection = cx_Oracle.Connection("cx_Oracle/dev@localhost/orcl") cursor = connection.cursor()
my_dict = {"foo": 1, "bar": 2}
try: stmt = cursor.prepare("SELECT dummy FROM dual WHERE dummy = :myvar") cursor.execute(stmt, {"myvar": my_dict})
except cx_Oracle.DatabaseError as exc: print(str(type(exc))) # <class 'cx_Oracle.NotSupportedError'> print(repr(exc)) # NotSupportedError('Variable_TypeByValue(): unhandled data type dict',) error, = exc.args # "error" is a str, NOT a cx_Oracle._Error object print("Oracle-Error-Code:", error.code) # AttributeError: 'str' object has no attribute 'code' print("Oracle-Error-Message:", error.message)
The documentation states:
With cx_Oracle every exception object has exactly one argument in the
args
tuple. This argument is acx_Oracle._Error
object...
Environment
- Python: 2.7.13 |Anaconda 4.3.1 (64-bit)
- cx_Oracle: 5.2.1
- Oracle client version: InstantClient 12.2 via rpm
- Oracle database version: 12.2
- OS: CentOS release 6.9 (Final)