pythonpython-3.xunicodeutf-8cx-oracle

UnicodeEncodeError: 'ascii' codec can't encode character 'xa0' in position 586: ordinal not in range(128)


I'm getting this error while inserting the data into the table. result_df has a column which contains different languages text in it and I tried to use encode('utf-8') but no use . I used following code:

result_df.Column_Name.str.encode('utf-8')
data1=result_df.values.tolist() 
conn = connection.__open__()
cursor = conn.cursor()
sqlstmt = 'SQL_stmt'
cursor.executemany(sqlstmt, data1). 
conn.commit()

any advices on this is appreciated


Solution

  • by using (encoding="UTF-8", nencoding="UTF-8") parameters in connect method . my issue is resolved.

    conn = cx.connect(user='username', password='****', dsn='dsn_data',encoding="UTF-8", nencoding="UTF-8")