Skip to content

Instantly share code, notes, and snippets.

@dchud
Created June 20, 2012 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dchud/2960200 to your computer and use it in GitHub Desktop.
Save dchud/2960200 to your computer and use it in GitHub Desktop.
voyager/oracle/django weirdness
# 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