(Migrated) How can I use environment variables?

(This message has been automatically imported from the retired mailing list)

Hi,

I’m trying to use enviroment variables in some some zato services.

I tried with importing ‘os’ module and using this command in the service.

foo = os.environ[“MY_LOCAL_VARIABLE”]

But when i set the enviroment variables and deploy the service,

service won’t deploying.

Could anybody can give me some information how to use enviroment
variables in a zato service.

Thanks a lot.

Best regards.
Ozgur

On 26/06/2015 09:00, Özgür Fırat Çınar wrote:

I tried with importing ‘os’ module and using this command in the service.

foo = os.environ[“MY_LOCAL_VARIABLE”]

But when i set the enviroment variables and deploy the service,

service won’t deploying.
(1) What do the logs say just after you’ve deployed it?

tail server1/logs/server.log
tail server2/logs/server.log

(2) Try running the service module directly from the command line:

/opt/zato/2.0.5/bin/py myservice.py

This will at least show you if there are any import errors or syntax errors.

(3) If the variable has not propagated to the environment where your
code runs, it will raise an error.

import os
os.environ[“MY_LOCAL_VARIABLE”]
Traceback (most recent call last):
File “”, line 1, in
File “/opt/zato/2.0.5/lib/python2.7/UserDict.py”, line 23, in getitem
raise KeyError(key)
KeyError: ‘MY_LOCAL_VARIABLE’

So it’s really a question of where you’re setting this environment
variable, and how you expect it to propagate all the way through gunicorn.

You are probably better off setting your configuration in redis:
https://zato.io/docs/progguide/kvdb.html

And there are more options described in this page:
https://zato.io/docs/progguide/service-local-config.html

Regards,

Brian.

On 26/06/15 10:16, Brian Candler wrote:

You are probably better off setting your configuration in redis:
https://zato.io/docs/progguide/kvdb.html

And there are more options described in this page:
https://zato.io/docs/progguide/service-local-config.html

There’s also os_environ stanza in server.conf files.

[os_environ]
hi=there

And then in services:

import os

hi = os.environ[‘hi’]

Hii again.
Surprisingly, when i tried again. It’s worked. Lots of thanks for quick
help and extra information.

Bests.
Ozgur

2015-06-26 11:23 GMT+03:00 Dariusz Suchojad dsuch@zato.io:

On 26/06/15 10:16, Brian Candler wrote:

You are probably better off setting your configuration in redis:
https://zato.io/docs/progguide/kvdb.html

And there are more options described in this page:
https://zato.io/docs/progguide/service-local-config.html

There’s also os_environ stanza in server.conf files.

[os_environ]
hi=there

And then in services:

import os

hi = os.environ[‘hi’]


Dariusz Suchojad

https://zato.io
ESB, SOA, REST, APIs and Cloud Integrations in Python