Python 2.7 connection to Oracle: loosing (Polish) characters

那年仲夏 提交于 2019-12-25 07:27:17

问题


I connect from Python 2.7 to Oracle data base. When I use:

cursor.execute("SELECT column1 FROM table").fetchall()]

I have got almost proper values for column1 because all Polish characters ("ęóąśłżćń") are converted to ascii one ("eoaslzcn"). Using another tool like SQLDeveloper and using the same select statement I get proper value.


回答1:


Try setting the environment variable NLS_LANG to your database language string, something like

os.environ['NLS_LANG'] = 'POLISH_POLAND.EE8MSWIN1250'



回答2:


@Mark Harrison - thank you very much ! It works! There is an exact instruction what I did:

I checked in Oracle what is the language:

SELECT USERENV ('language') FROM DUAL

The response was:

POLISH_POLAND.UTF8

Then I changed NLS_LA value in Python:

os.environ['NLS_LANG'] = 'POLISH_POLAND.UTF8'

Using

print "%s, %s" % (name, surname)

and "> file.txt" in command line I obtained a (proper) file in utf8.



来源:https://stackoverflow.com/questions/39780090/python-2-7-connection-to-oracle-loosing-polish-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!