DPY-3002: Python value of type “int64” is not supported; I need to combine my code with InputHandler apparently but I have hard problem combining them

  Kiến thức lập trình

I have the below code which I use cx_oracle to pull from data base and pass variable from a csv file. the variable ‘unitid’ does have dtype is int64 but I tried multiple conversions and non worked.

Basically the below code has to be combined with the following code after it according to similar questions but I couldn’t put it together,

this is my code:


df = pd.read_csv(r"C:UsersVosouaDesktopIngenco_Offers_csv2.csv") 

df=df.dropna()

unitid=df['UNITSCHEDULEID'].unique()


TNS_Admin = os.environ.get('xxxxx')
oracledb.defaults.config_dir = TNS_Admin
pw = input(f'Enter password: ')
connection = oracledb.connect(user='xxxxx', password= pw, dsn="xxxxxx")

query = """SELECT HOUR, UNITSCHEDULEID, VERSIONID, MINRUNTIME
FROM  int_Stg.xxxxxx
WHERE Hour in ({hour_binds})
AND   UnitScheduleId in ({id_binds})""".format(
  hour_binds=",".join((f":{idx}" for idx, _ in enumerate(hour, 1))),
  id_binds=",".join((f":{idx}" for idx, _ in enumerate(unitid, len(hour) + 1))),
)

res = connection.cursor().execute(query, (*hour, *unitid)).fetchall()

and I the second code is

def InConverter(value):
    return int(value)  # or whatever is needed to convert from numpy.int64 to an integer

def InputTypeHandler(cursor, value, num_elements):
    if isinstance(value, numpy.int64):
        return cursor.var(int, arraysize=num_elements, inconverter=InConverter)

cursor().inputtypehandler = InputTypeHandler

LEAVE A COMMENT