Python Forum

Full Version: Error TypeError: output_type_handler() takes 2 positional arguments but 6 were given
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all, I'm running a python code that was working before with older version. Now using 3.10 I'm gettin error below:

TypeError: output_type_handler() takes 2 positional arguments but 6 were given
The block is below:

return_code = 0

try:
    with tempfile.TemporaryDirectory() as tmp_dir:
        import cx_Oracle as oracledb
        import xml.etree.ElementTree as ET
        import os
        import subprocess

        def output_type_handler(
                cursor,
                default_type):
            if default_type == oracledb.CLOB:
                return cursor.var(
                    oracledb.LONG_STRING,
                    arraysize=cursor.arraysize)
            if default_type == oracledb.BLOB:
                return cursor.var(
                    oracledb.LONG_BINARY,
                    arraysize=cursor.arraysize)

        conn = oracledb.connect("/", mode=oracledb.SYSDBA)
        conn.outputtypehandler = output_type_handler
        prev_name = None
        cursor = conn.cursor()
        cursor.execute(
            "select name, cval from v$view where conftype='XYZ' order by name desc")
I'm returning only 2 columns in query and declared 2 type handler columns so not sure from where it was getting "6 arguments given".
(Oct-17-2022, 06:23 PM)paulo79 Wrote: [ -> ]Hi all, I'm running a python code that was working before with older version. Now using 3.10 I'm gettin error below:

TypeError: output_type_handler() takes 2 positional arguments but 6 were given
The block is below:

return_code = 0

try:
    with tempfile.TemporaryDirectory() as tmp_dir:
        import cx_Oracle as oracledb
        import xml.etree.ElementTree as ET
        import os
        import subprocess

        def output_type_handler(
                cursor,
                default_type):
            if default_type == oracledb.CLOB:
                return cursor.var(
                    oracledb.LONG_STRING,
                    arraysize=cursor.arraysize)
            if default_type == oracledb.BLOB:
                return cursor.var(
                    oracledb.LONG_BINARY,
                    arraysize=cursor.arraysize)

        conn = oracledb.connect("/", mode=oracledb.SYSDBA)
        conn.outputtypehandler = output_type_handler
        prev_name = None
        cursor = conn.cursor()
        cursor.execute(
            "select name, cval from v$view where conftype='XYZ' order by name desc")
I'm returning only 2 columns in query and declared 2 type handler columns so not sure from where it was getting "6 arguments given".

Pleae ignore. I found the error.

Just had to add all signatures like :

def output_type_handler(cursor, name, default_type, size, precision, scale):
            if default_type == oracledb.DB_TYPE_CLOB:
                return cursor.var(oracledb.DB_TYPE_LONG, arraysize=cursor.arraysize)
            if default_type == oracledb.DB_TYPE_BLOB:
                return cursor.var(oracledb.DB_TYPE_LONG_RAW, arraysize=cursor.arraysize)