OpenInformix / IfxPy

Informix native Python driver for scalable enterprise and IoT solutions.
Other
46 stars 22 forks source link

problem with cron (SQLCODE=-23101) #36

Closed zdenop closed 4 years ago

zdenop commented 4 years ago

I try to run script using IfxPy with cron. My script works when I run it under user. But it fails when it iss run from cron. I was able to replicate problme with sudo -H:

sudo -H python3 bots/test/cn_test_cron.py
[sudo] password for root:
Traceback (most recent call last):
  File "/usr/lib64/python3.6/site-packages/IfxPyDbi.py", line 503, in connect
    conn = IfxPy.connect(ConStr, '', '', conn_options)
Exception: [Informix][Informix ODBC Driver][Informix]Unspecified System Error =  -23101. SQLCODE=-23101

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "bots/test/cn_test_cron.py", line 9, in <module>
    connection = dbapi2.connect(con_str)
  File "/usr/lib64/python3.6/site-packages/IfxPyDbi.py", line 506, in connect
    raise _get_exception(inst)
IfxPyDbi.Error: ifx_pydb::Error: [Informix][Informix ODBC Driver][Informix]Unspecified System Error =  -23101. SQLCODE=-23101

Any idea how to fix it?

zdenop commented 4 years ago

OK, so it tuns out that INFORMIXDIR is not set when running script under cron. Quick solution is:

if not os.getenv("INFORMIXDIR"):
        os.environ['INFORMIXDIR'] = '/opt/IBM/Informix_Client-SDK'

Anyway better error message would helped, so I keep the issue open.

jsagrera commented 4 years ago

That's a good point, but the thing is that the errors messages are located inside INFORMIXDIR, so if we can't find INFORMIXDIR because it is not set, there is no way to give you a better message ;)

The clue is in the "Unspecified System Error". The driver (Informix ODBC driver) knows that there was an error (23101) but it is unable to get the text for the error. -23101 correspond to "Unable to load locale categories.".

zdenop commented 4 years ago

What about to connect function (or other relevant place) some check:

if not os.getenv("INFORMIXDIR"):
    raise InterfaceError("Environment variable INFORMIXDIR not set")