I posted something similar to this in this thread:
Rocket U2 | UniVerse & UniData
| Rocketsoftware | |||||||
|
|||||||
I have a variable defined in /etc/environment:
[hcortiguera@catalogo20 ~]$ cat /etc/environmentOPENAI_API_KEY=MY_API_KEY
I can read it from command-line Python:
[hcortiguera@catalogo20 ~]$ /u2/uv/python/bin/python3Python 3.9.2 (default, Jun 15 2021, 01:30:50)[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import os>>> os.environ['OPENAI_API_KEY']'MY_API_KEY'
But I can't read it when I call Python from BASIC
NOMBRE.VAR.ENTORNO='OPENAI_API_KEY'
NOMBRE.SCRIPT='consultaVariableEntorno'NOMBRE.FUNCION='get_var_entorno'
RESPUESTA=PyCallFunction(NOMBRE.SCRIPT,NOMBRE.FUNCION,NOMBRE.VAR.ENTORNO)CRT '[EJECUTADO]'CRT '[':RESPUESTA:']'
The Python code:
import os
def get_var_entorno(var_entorno): return str(os.environ.get(var_entorno, '?'))
The output from BASIC:
[EJECUTADO]
[?]
Why the Python interpreter is not reading /etc/environment?
------------------------------
Héctor Cortiguera
Quiter Servicios Informaticos SL
------------------------------