public
Created

voyager/oracle/django weirdness

  • Download Gist
gistfile1.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
# 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-'

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.