Note, this email has been cc'd back to mod_wsgi mailing list. Please
use the mailing list for further followups. List can be found at:

  http://groups.google.com/group/modwsgi?lnk=srg

See response to question below.

2010/1/9 jérémy PARIS <[email protected]>:
>
> Hi,
>
> My name is Jérémy and I am a french python developper.
>
> I have a site which use repoze.bfg + mod_wsgi.
>
> I have to get the os.environ['PATH'] to execute some programs not in
> /usr/bin.
>
> But when I do os.environ.get('PATH') it return to me an incorrect path
> (different than the python os.environ.get('PATH') or my $PATH user)
>
> extract of os.environ whith mod_sgi
> {'USERNAME': 'zope', 'LANG': 'en_US.utf8', 'TERM': 'xterm', 'SHELL':
> '/bin/bash',[..] 'LOGNAME': 'zope', 'USER': 'zope', 'INPUTRC':
> '/etc/inputrc', 'PATH': '/sbin:/usr/sbin:/bin:/usr/bin', 'MAIL':
> '/var/spool/mail/zope', 'SUDO_USER': 'zope', [..] 'HOME': '/home/zope', '_':
> '/usr/sbin/httpd'}
>
> extract of os.environ whith python
> {'USERNAME': 'zope', 'LANG': 'en_US.utf8', 'TERM': 'xterm', 'SHELL':
> '/bin/bash',[..] 'LOGNAME': 'zope', 'USER': 'zope', 'INPUTRC':
> '/etc/inputrc', 'PATH':
> '/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/usr/local/sbin',[...] 'HOME':
> '/home/zope, ''_': '/usr/local/python/py254/bin/python'}
>
> So I compile mod_wsgi with:
> ./configure --with-apxs=/usr/sbin/apxs
> --with-python=/usr/local/python/py254/bin/python
>
> So why in WSGI os.environ.get('PATH') was différent ?

When you run command line Python it is running from your own user
environment and therefore inherits all the user environment variables.

When Apache is run t is run as special daemonised service from
operating system init scripts. It therefore inherits only environment
available on operating system startup. Apache further scrubs that
environment to a degree from memory as well.

As such, if you really need to set environment variables, they should
be set from the WSGI script file. For example:

  import os
  os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

Note though that I would not encourage setting of PATH environment
variable. It is much much better to ensure that when executing
programs from inside of your application that you set the full
absolute path to the program to be executed and not rely on it being
found on the PATH.

So, instead of using:

  os.system('ls')

you are much better off using:

  os.system('/bin/ls')

Similar issues occur with dealing directly with any file system path,
eg, reading files. That is, you should always use absolute paths and
not rely on current working directory being a specific value or of
file being found on some path dictated by a user environment variable.
In the latter it isn't always possible, but it is a good aim as far as
portability goes.

Graham
-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/modwsgi?hl=en.


Reply via email to