gpt4 book ai didi

python - 如何修复Python中的 'TypeError: expecting string or bytes object'错误

转载 作者:行者123 更新时间:2023-12-01 08:00:44 28 4
gpt4 key购买 nike

我想在表中插入一行。但我得到了 TypeError: waiting string or bytes object 这个错误。

Traceback (most recent call last): File "d:\Git\Repos\mavi\oracle_connection.py", line 19, in c.prepare(QUERY,{"expr":expr, "expr2":expr2}) TypeError: expecting string or bytes object

import cx_Oracle
dsn_tns = cx_Oracle.makedsn(***)
conn = cx_Oracle.connect(***)
c = conn.cursor()

expr = bytes('', 'utf-8')
expr2 = bytes('ML_TEST', 'utf-8')

QUERY = '''
INSERT INTO dev_log (LOG, SQ_DEV_LOG_ID, LF_TEKLIF_WS, PACKAGE BODY, LINE_NO)
VALUES
(:expr,:expr,:expr2,:expr,:expr)
'''

rows = []

c.prepare(QUERY,{"expr":expr, "expr2":expr2})
c.executemany(None, rows)
conn.commit()

conn.close()

如何解决这个问题?

最佳答案

尝试:

c.prepare(QUERY)      
c.executemany(None, [{"expr":expr, "expr2":expr2}])

从文档来看,您似乎应该将参数传递给 executemany,而不是 prepare

https://cx-oracle.readthedocs.io/en/latest/cursor.html

关于python - 如何修复Python中的 'TypeError: expecting string or bytes object'错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55747709/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com