1

I want to insert a row into table. But i got TypeError: expecting string or bytes object this error.

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()

How can i fix this problem?

8
  • Your posted code only contains 21 lines. Are you sure you're not leaving something out? Commented Apr 18, 2019 at 14:04
  • @HampusLarsson yes there was comments, i edited Commented Apr 18, 2019 at 14:07
  • Şevval, can you descibe your table so that we can see the data types of the columns ? Commented Apr 18, 2019 at 14:43
  • @BarbarosÖzhan with order <CLOB> , int , string, string, int Commented Apr 18, 2019 at 14:46
  • I think, this explains the issue, since, substitution variable expr is used for integer, string and clob at the same time. Commented Apr 18, 2019 at 14:49

1 Answer 1

1

Try:

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

From the docs, it looks like you should be passing your parameters to executemany, not prepare.

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

Sign up to request clarification or add additional context in comments.

3 Comments

Now it gives this error " c.executemany(None, [{"expr":expr, "expr2":expr2}]) cx_Oracle.DatabaseError: ORA-00917: missing comma "
That's probably because your column "PACKAGE BODY" has a space in the name, you should specify it in quotes.
how can i fix it? how should i represent it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.