Reputation: 41
I am trying to insert dataframe to oracle database using to_sql. Below is the code:
engine = create_engine('oracle+cx_oracle://'+username+':'+password+'@'+host+':'+port+'/'+sid) df.to_sql(name = table.lower(),schema=schema,con =engine,if_exists = 'replace', index=False)
I am getting below error: UnicodeEncodeError: 'ascii' codec can't encode character '\u2013' in position 81: ordinal not in range(128)
can someone please help on this.
Upvotes: 0
Views: 505
Reputation: 8518
Probably your database is UTF8 and you did not export your NLS_LANG variable in your session:
So I would try to first export your NLS_LANG to the character set you have in your database:
#export NLS_LANG=American_America.AL32UTF8
Then I would try to change your connection in cx_Oracle.connect method:
connection = cx_Oracle.connect("user/password@connectString",
encoding="UTF-8", nencoding="UTF-8")
As you are using to_sql , you might try this before you try your connection
import os
os.environ["NLS_LANG"] = 'YOUR_NLS_LANG_VARIABLE'
Upvotes: 0