Created
June 20, 2012 14:38
-
-
Save dchud/2960200 to your computer and use it in GitHub Desktop.
voyager/oracle/django weirdness
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# debugging a problem ticketed at https://github.com/gwu-libraries/launchpad/issues/22 | |
# note: reopened django ticket w/comment https://code.djangoproject.com/ticket/15313#comment:4 | |
# t.py script: | |
import cx_Oracle | |
dsn_tns = cx_Oracle.makedsn('oracle.example.com', 1521, 'VGER') | |
conn = cx_Oracle.connect('user', 'pass', dsn_tns) | |
c = conn.cursor() | |
r = c.execute(""" | |
SELECT wrlcdb.getbibtag(7325981, '880') | |
FROM bib_text | |
WHERE bib_id=7325981 | |
""") | |
d = r.fetchone() | |
# executed from ipython (no django env). this is the correct value. | |
In [1]: %edit t.py | |
In [2]: d[0] | |
Out[2]: '100-01/$1 \xe6\x9d\x91\xe4\xb8\x8a\xe6\x98\xa5\xe6\xa8\xb9, 1949-' | |
# executed from django env. this is incorrect. | |
In [1]: %edit t.py | |
In [2]: d[0] | |
Out[2]: '100-01/$1 \xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd, 1949-' | |
# hmm, more details, it's not *just* django. from ipython (no django env). both are correct. | |
In [2]: %run t.py | |
In [3]: d[0] | |
Out[3]: '100-01/$1 \xe6\x9d\x91\xe4\xb8\x8a\xe6\x98\xa5\xe6\xa8\xb9, 1949-' | |
In [4]: import django | |
In [5]: %run t.py | |
In [6]: d[0] | |
Out[6]: '100-01/$1 \xe6\x9d\x91\xe4\xb8\x8a\xe6\x98\xa5\xe6\xa8\xb9, 1949-' | |
# okay, narrowed it down further. django's oracle driver is forcing NLS_LANG = '.UTF8' | |
# executed from django env. first is incorrect, second is correct. | |
In [1]: import os | |
In [2]: os.environ['NLS_LANG'] | |
Out[2]: '.UTF8' | |
In [3]: %run t.py | |
In [4]: d[0] | |
Out[4]: '100-01/$1 \xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd, 1949-' | |
In [5]: os.environ['NLS_LANG'] = '.US7ASCII' | |
In [6]: %run t.py | |
In [7]: d[0] | |
Out[7]: '100-01/$1 \xe6\x9d\x91\xe4\xb8\x8a\xe6\x98\xa5\xe6\xa8\xb9, 1949-' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment