I am getting:

[01000] [unixODBC][Driver Manager]Can't open lib '/usr/local/nz/lib64/libnzodbc.so' : file not found (0) (SQLDriverConnect)"

error while creating connection using PyODBC. This works fine when I use it via Django Development server. But on using it via. Gunicorn and Nginx, it fails.

I faced this issue in the past (while configuring the Development server) when:

  1. Some of the libraries needed by UnixODBC were missing. Since, it is working with Django development server, this couldn't be the issue
  2. When environment variables PATH and LD_LIBRARY_PATH do not had the path to my driver.

Most likely I think 2nd is the cause. I tried setting up the environment variables in /etc/profile and /etc/environment but no luck. Does anyone have idea regarding what might be wrong here?

It has nothing to do with Gunicorn as directly running the gunicorn server using:

gunicorn --bind my_project.wsgi:application

works fine. Issue is while communication with Nginx via wsgi.

All the required environment methods are setted up correctly:

mquadri@MY_HOST:/tmp/webadmin$ env

All the related dependencies are already installed. Below is the ouput of ldd in case someone might find it useful:

mquadri@MY_HOST:/tmp/webadmin$ ldd /usr/local/nz/lib64/libnzodbc.so
    linux-vdso.so.1 =>  (0x00007fff96dfa000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f286f0f1000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f286edeb000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f286ebcc000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f286e9c8000)
    libkrb5.so.3 => /usr/local/nz/lib64/libkrb5.so.3 (0x00007f286e7e8000)
    libkrb5support.so.0 => /usr/local/nz/lib64/libkrb5support.so.0 (0x00007f286e6da000)
    libcom_err.so.3 => /usr/local/nz/lib64/libcom_err.so.3 (0x00007f286e5d7000)
    libk5crypto.so.3 => /usr/local/nz/lib64/libk5crypto.so.3 (0x00007f286e494000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f286f806000)
    libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f286e278000)

If I set these environment variables explicitly in settings.py development server runs fine, but nginx gives Internal Server Error.

  • What are the permissions for /usr/local/nz/lib64/libnzodbc.so? – Tero Kilkanen Nov 14 '16 at 17:48
  • I thought it might be permission related issue, so I changed it to 777, along with the complete path to it from nz – Moinuddin Quadri Nov 14 '16 at 17:59
  • It looks to me that any of the environment variable that I am setting explicitly for ODBC is been overridden by any of the Nginx variable. – Moinuddin Quadri Nov 14 '16 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.