Tagged and released mod_wsgi 2.0c2.

223 views
Skip to first unread message

Graham Dumpleton

unread,
Nov 8, 2007, 5:40:41 AM11/8/07
to mod...@googlegroups.com
Second release candidate for mod_wsgi 2.0 is now available. For details see:

http://code.google.com/p/modwsgi/wiki/ChangesInVersion0200

This refresh fixes a bug in WSGIPythonPath which would cause a crash
when used on some platforms, plus issues with thread stack size
configuration which made module not portable between Apache worker and
prefork MPMs.

The behaviour of WSGIPythonPath has also changed from 2.0c1 in that
its value is not inherited by daemon processes. Instead you need to
separately use 'python-path' option for WSGIDaemonProcess to specify
additional Python module directories for daemon processes.

Also added new WSGIPythonEggs directive and corresponding
'python-eggs' option for WSGIDaemonProcess to specify Python Egg cache
directory. This serves the same role as having set PYTHON_EGG_CACHE
directive environment variable.

Finally, the WSGIPythonExecutable directive has been removed. This
didn't work on Windows or MacOSX as wasn't really being used as
intended. If it is necessary to override where a Python installation
is, the WSGIPythonHome directive should be used instead.

The combination of using WSGIPythonHome and the WSGIPythonPath
directive or 'python-path' option for daemon processes should make it
much easier to use mod_wsgi with Python virtual environments.

Enjoy.

Graham

gert

unread,
Nov 8, 2007, 8:34:12 AM11/8/07
to modwsgi
Whohoo :)

gert

unread,
Nov 8, 2007, 12:55:47 PM11/8/07
to modwsgi
Waiting for Adal to do his magic stuff :)
http://adal.chiriliuc.com/mod_wsgi/

gert

unread,
Nov 8, 2007, 7:20:23 PM11/8/07
to modwsgi
The wsgi path works on ubuntu whohoo :) but i have some other error
now

[Fri Nov 09 01:13:48 2007] [info] mod_wsgi (pid=6099): Adding '/home/
gert/www/trunk/wsgi' to path.
[Fri Nov 09 01:13:48 2007] [info] [client 192.168.1.18] mod_wsgi
(pid=6099, process='', application='localhost|/upload/servlet'):
Loading WSGI
[Fri Nov 09 01:13:49 2007] [error] [client 192.168.1.18] mod_wsgi
(pid=6099): Exception occurred processing WSGI script '/home/gert/www/
trunk/
[Fri Nov 09 01:13:49 2007] [error] [client 192.168.1.18] TypeError:
sequence of string values expected, value of type array.array found,
refer
[Fri Nov 09 01:14:00 2007] [info] mod_wsgi (pid=6183): Create
interpreter 'localhost|/download/servlet'.
[Fri Nov 09 01:14:00 2007] [info] mod_wsgi (pid=6183): Adding '/home/
gert/www/trunk/wsgi' to path.
[Fri Nov 09 01:14:00 2007] [info] [client 192.168.1.18] mod_wsgi
(pid=6183, process='', application='localhost|/download/servlet'):
Loading WS
[Fri Nov 09 01:14:00 2007] [error] [client 192.168.1.18] mod_wsgi
(pid=6183): Exception occurred processing WSGI script '/home/gert/www/
trunk/
[Fri Nov 09 01:14:00 2007] [error] [client 192.168.1.18] TypeError:
sequence of string values expected, value of type array.array found

Graham Dumpleton

unread,
Nov 8, 2007, 7:49:13 PM11/8/07
to mod...@googlegroups.com

A WSGI application is meant to return an iterable value where the
yielded values must only be strings. You seem to be returning an
iterable that contains an 'array.array' object instance.

The simplest example of an iterable is a list. Ie.,

[ "string1", "string2", "string3" ]

Your code appears to be returning:

[ array.array('c', 'string1') ]

which will be rejected.

What is your code trying to do? Why are you using 'array' module?

Graham

gert

unread,
Nov 8, 2007, 8:13:50 PM11/8/07
to modwsgi

On Nov 9, 1:49 am, "Graham Dumpleton" <graham.dumple...@gmail.com>
wrote:

It don't know :) I didn't change code only mod_wsgi

This all my code

http://appwsgi.googlecode.com/svn/trunk/wsgi/


Graham Dumpleton

unread,
Nov 8, 2007, 8:25:15 PM11/8/07
to mod...@googlegroups.com
But what is the specific URL you are accessing which is causing this
error returning?

Is it returning image data from PIL, or something from an XML library,
from a database, or from some other source?

Ie., what is generating the data being returned as obviously some
third party module you are using is generating it and you haven't
ensured you use str() to convert it back to a string object.

Graham

On 09/11/2007, gert <gert.c...@gmail.com> wrote:
>
>
>

Litnimax

unread,
Nov 8, 2007, 8:40:56 PM11/8/07
to modwsgi
I have just downloaded version 2 and it complains on
WSGIPythonExecutable...
Reverted back to 1.2 - all ok.
Seems WSGIPythonExecutable is not supported yet.
Please advise.

Regards,
Max.

gert

unread,
Nov 8, 2007, 8:45:44 PM11/8/07
to modwsgi
there are two things that don't work on my ubuntu box 2.0.c2 because i
did something stupid probably, but do work on my windows pc with
2.0.c1

first when downloading a image from mysql i get a empty file text/x-
python file instead of a png file ? So i assume one of the errors is
from my download.py

second error is from session.py that doesn't seem to get my cookie on
my web browser resulting in my self made permission denied alert
trying to aces data with out my cookie that i did not get properly

I don't get 500 error's only weird stuff that i do not have on my
windows pc with the same source code

So i probably mest up my source code somehow on my ubunut pc, i will
check again

On Nov 9, 2:25 am, "Graham Dumpleton" <graham.dumple...@gmail.com>
wrote:


> But what is the specific URL you are accessing which is causing this
> error returning?
>
> Is it returning image data from PIL, or something from an XML library,
> from a database, or from some other source?
>
> Ie., what is generating the data being returned as obviously some
> third party module you are using is generating it and you haven't
> ensured you use str() to convert it back to a string object.
>
> Graham
>

Graham Dumpleton

unread,
Nov 8, 2007, 8:51:27 PM11/8/07
to mod...@googlegroups.com

As per the 2.0 change notes it has been removed.

This didn't work on Windows and MacOSX and was being used by people as
a mechanism for doing virtual environments when it was only intended
as a fail safe to get around issues with multiple versions of Python
being installed on a box. The same thing could be done though in a
much better way using WSGIPythonHome, so rather than provide two ways
of doing the same thing, albeit where one only works on some systems,
I cut it back to one way to avoid confusion.

So, if you had Python installed in /usr/local/bin/pythonX.Y, whereby
the Python lib directory was /usr/local/lib/pythonX.Y, instead of
using:

WSGIPythonExecutable /usr/local/bin/pythonX.Y

use:

WSGIPythonHome /usr/local

The WSGIPythonExecutable directive was only ever used as an anchor
point by Python to work out what WSGIPythonHome indicates explicitly.

That is, what Python was doing to calculate the Python prefix
directory from WSGIPythonExecutable was to go:

os.path.join(os.path.dirname(os.path.dirname(path)), 'lib', 'pythonX.Y')

Note that WSGIPythonHome was in mod_wsgi 1.0 and will work there as well.

If for some reason WSGIPythonHome doesn't achieve the same affect, do
let me know, as have only disabled the WSGIPythonExecutable code or
now and haven't actually removed it. You should be able to do the same
thing with WSGIPythonHome though.

When I get a chance I intend blogging about
WSGIPythonHome/WSGIPythonPath and how to use it with virtual
environments.

Graham

gert

unread,
Nov 8, 2007, 9:39:20 PM11/8/07
to modwsgi
To sleepy now... anyway this is in my mysql picture blob "array('c',
'\x89PNG...." so i think i found my array instead of string
reference.

snif every time you think your are finally done crap happens...

nstei...@gmail.com

unread,
Nov 9, 2007, 7:02:59 AM11/9/07
to modwsgi

Graham Dumpleton wrote:
> Second release candidate for mod_wsgi 2.0 is now available. For details see:
>
> http://code.google.com/p/modwsgi/wiki/ChangesInVersion0200
>

PKGBUILD for Archlinux is updated :
http://aur.archlinux.org/packages.php?do_Details=1&ID=13521

Nicolas

gert

unread,
Nov 9, 2007, 8:57:26 AM11/9/07
to modwsgi

upgraded my ubuntu to gusty including a new mysql python apache and
now without changing code my file uploads seem to work again, only my
cookie is still not doing the same on windows.

Seems like there are other things to consider when writing wsgi code?

gert

unread,
Nov 9, 2007, 9:05:43 AM11/9/07
to modwsgi

Wait a minute i do a time check in my sql statements so i think it has
to do with the hole UTC GMT time stuff and my cookie get rejected
because it is expired.

Ubuntu = UTC
Windows = GMT

gert

unread,
Nov 9, 2007, 9:31:17 AM11/9/07
to modwsgi

No scratch that cookies are exactly the same....

gert

unread,
Nov 9, 2007, 9:41:20 AM11/9/07
to modwsgi

Is there something different with environ.get('HTTP_COOKIE','') in
2.0c2 ? or on linux and windows ?

gert

unread,
Nov 9, 2007, 10:41:42 AM11/9/07
to modwsgi

oops :) i found it i didn't set my gid column to 1

gert

unread,
Nov 9, 2007, 10:53:19 AM11/9/07
to modwsgi
I can confirm 2.0c2 works fine for me now on ubuntu :)

Bernd Zeimetz

unread,
Nov 9, 2007, 11:32:48 AM11/9/07
to mod...@googlegroups.com
gert wrote:
> I can confirm 2.0c2 works fine for me now on ubuntu :)

could you _please_ stop talking to yourself on the list?

Thanks.


--
Bernd Zeimetz
<be...@bzed.de> <http://bzed.de/>

Bernd Zeimetz

unread,
Nov 9, 2007, 11:36:05 AM11/9/07
to mod...@googlegroups.com
Graham Dumpleton wrote:
> Second release candidate for mod_wsgi 2.0 is now available. For details see:
>
> http://code.google.com/p/modwsgi/wiki/ChangesInVersion0200

As ftp-master.debian.org is still broken down due to a massive hardware
failure there's no way to update the Debian package yet.
If somebody is interested I can provide a package or at least the
sources you need to build the .deb by yourself.

Adal Chiriliuc

unread,
Nov 9, 2007, 5:17:45 PM11/9/07
to modwsgi
The win32 builds are now available. Sorry for the delay.

Changes required to compile: at line 3012 the following code needs to
be deleted:

struct passwd *pwent;
pwent = getpwuid(geteuid());

gert

unread,
Nov 9, 2007, 8:22:59 PM11/9/07
to modwsgi
works perfectly for me thanks :)

So you just deleted some Graham code without putting anything in
return and it still works ? windows is something amazing isn't it :)

PS can you compile it for 64 bit too ?

Adal Chiriliuc

unread,
Nov 10, 2007, 2:58:33 AM11/10/07
to modwsgi
That variable wasn't used anywhere and the internet suggests that the
two function calls don't have side effects, so it should be safe.

Sorry, no 64 bit builds :( Too much of a hassle.

Litnimax

unread,
Nov 10, 2007, 5:18:31 AM11/10/07
to modwsgi
WSGIPythonHome works. Thanks.
But what is the sense of setting it globally in http.conf??

* Apache2 has detected a syntax error in your configuration files:
Syntax error on line 151 of /etc/apache2/vhosts.d/vhosts.conf:
WSGIPythonHome cannot occur within <VirtualHost> section

What if I have project that depends on python2.5 installed in custom
path and all other projects using system wide python? This is my exact
situation.
I would like to define this on VirtualHost level.

Please advise.

Regards,

Litnimax

unread,
Nov 10, 2007, 5:49:30 AM11/10/07
to modwsgi
>
> If for some reason WSGIPythonHome doesn't achieve the same affect, do
> let me know, as have only disabled the WSGIPythonExecutable code or
> now and haven't actually removed it. You should be able to do the same
> thing with WSGIPythonHome though.

Please disregard my previous post. It does not work :-)
I have somple wsgi script below. Apache has the following conf.
directives:

LoadModule wsgi_module modules/mod_wsgi.so
WSGIPythonOptimize 2
WSGIPythonHome /home/asterisk/python2.5

snowflake ~ # ls /home/asterisk/python2.5
bin include lib man
snowflake ~ # ls /home/asterisk/python2.5/bin/python
/home/asterisk/python2.5/bin/python
snowflake ~ #

When I run it I get:
[Sat Nov 10 10:34:59 2007] [debug] mod_wsgi.c(7147): mod_wsgi
(pid=26733): Starting thread 4 in daemon process 'hvpn'.
[Sat Nov 10 10:34:59 2007] [debug] mod_wsgi.c(7147): mod_wsgi
(pid=26733): Starting thread 5 in daemon process 'hvpn'.
[Sat Nov 10 10:34:59 2007] [info] mod_wsgi (pid=26734): Create
interpreter 'hvpnxxx.com|'.
[Sat Nov 10 10:34:59 2007] [info] [client 195.242.215.60] mod_wsgi
(pid=26734, process='hvpn', application='vpnxxx.com|'): Loading WSGI
script '/home/asterisk/rmanager/web-script/wsgi_app.py'.
[Sat Nov 10 10:34:59 2007] [error] [client 195.242.215.60] mod_wsgi
(pid=26734): Target WSGI script '/home/asterisk/rmanager/web-script/
wsgi_app.py' cannot be loaded as Python module.
[Sat Nov 10 10:34:59 2007] [error] [client 195.242.215.60] mod_wsgi
(pid=26734): Exception occurred processing WSGI script '/home/asterisk/
rmanager/web-script/wsgi_app.py'.
[Sat Nov 10 10:34:59 2007] [error] Traceback (most recent call last):
[Sat Nov 10 10:34:59 2007] [error] File "/home/asterisk/rmanager/web-
script/wsgi_app.py", line 1, in ?
[Sat Nov 10 10:34:59 2007] [error] import os, sys
[Sat Nov 10 10:34:59 2007] [error] *ImportError: No module named os*

If I compile mod_wsgi --with-python /home/asterisk/python2.5/bin/
python all works ok.
If I set WSGIPythonHome to non-existent directory I get same error "No
module named os".
So it seems that mod_wsgi loads python binary from path found at
compilation time. So in my case it picks up python2.4 and when set
WSGIPythonHome it tries to load os module from 2.5!

My script:

import os, sys
sys.path.append('/home/asterisk/rmanager') # should be set in
WSGIPythonPath instead.
os.environ['DJANGO_SETTINGS_MODULE'] = 'rmanager.settings'

#XXX: add logging to r manager
# WSGI app is not allowed to write to stdout.
sys.stdout = sys.stderr

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()


Litnimax

unread,
Nov 10, 2007, 5:54:09 AM11/10/07
to modwsgi
Also it does not respect WSGIPythonPath.
If I comment

import os, sys
#sys.path.append('/home/asterisk/rmanager')
os.environ['DJANGO_SETTINGS_MODULE'] = 'rmanager.settings'

and add WSGIPythonPath /home/asterisk/rmanager to http.conf I get:
[Sat Nov 10 10:53:05 2007] [error] [client x..x.x. EnvironmentError:
Could not import settings 'rmanager.settings' (Is it on sys.path? Does
it have syntax errors?): No module named rmanager.settings

So seems WSGIPythonPath is not doing its job.

Regards,

Max.

gert

unread,
Nov 10, 2007, 6:43:26 AM11/10/07
to modwsgi

Riscking to say something stupid again, does this work ?

import os, sys, rmanager
os.environ['DJANGO_SETTINGS_MODULE'] = rmanager.settings

Bernd Zeimetz

unread,
Nov 10, 2007, 8:29:37 AM11/10/07
to mod...@googlegroups.com

> If I compile mod_wsgi --with-python /home/asterisk/python2.5/bin/
> python all works ok.
> If I set WSGIPythonHome to non-existent directory I get same error "No
> module named os".
> So it seems that mod_wsgi loads python binary from path found at
> compilation time. So in my case it picks up python2.4 and when set
> WSGIPythonHome it tries to load os module from 2.5!

You _have_ to build mod_wsgi using the python version you're using for
your applications. Using a different version and setting the home
directory to some other version can't work.

Bernd Zeimetz

unread,
Nov 11, 2007, 6:25:46 PM11/11/07
to mod...@googlegroups.com
Bernd Zeimetz wrote:
> Graham Dumpleton wrote:
>> Second release candidate for mod_wsgi 2.0 is now available. For details see:
>>
>> http://code.google.com/p/modwsgi/wiki/ChangesInVersion0200
>
> As ftp-master.debian.org is still broken down due to a massive hardware
> failure there's no way to update the Debian package yet.
> If somebody is interested I can provide a package or at least the
> sources you need to build the .deb by yourself.

uploaded a few minutes ago, should hit experimental soon.

Reply all
Reply to author
Forward
0 new messages