General Question

7 views
Skip to first unread message

Joe Hughes

unread,
Feb 8, 2010, 10:21:42 AM2/8/10
to mod...@googlegroups.com
All,

I'm a bit confused.  I have two files

test_ajax_mod_wsgi.html
hello_server.wsgi

And I'm not getting what I expect.  I get this error

XML response error

Content-type:text/plain

Response: #!/usr/local/bin/python3 import sys import time def index(req): s = " " return s


when I send an AJAX request to the server.  This is the output of the access_log

141.232.2.115 - - [08/Feb/2010:10:06:28 -0500] "GET /netboss/test_ajax_mod_python.html HTTP/1.1" 200 3183
141.232.2.115 - - [08/Feb/2010:10:06:31 -0500] "POST /netboss/hello_server.wsgi HTTP/1.1" 200 154

It appears that my understanding is incomplete since instead of getting XML which shows the fixed time I get the above error.  Here is the hello_server.wsgi script

#! /usr/local/bin/python3

import sys
import time

def index(req):
s = "<?xml version=\"1.0\"?> <server time=\"2010-02004 12:00:00\"></server>"
return s

I'm basing this on the code from van der mewes http://vandermerwe.co.nz/?p=9, which was written for mod_python, but I don't see a reason it shouldn't work.
Your help in understanding this is appreciated.

Thanks,
Joe

Carl Nobile

unread,
Feb 8, 2010, 10:29:52 AM2/8/10
to mod...@googlegroups.com
If it was written for mod_python and you don't make the appropriate
changes for mod_wsgi it will not work at all. You must return a python
list object from the hook script in your care 'hello_server.wsgi', but
this is not all. It's really very simple, but it is not at all like
mod_python.

You really need to read the docs: http://code.google.com/p/modwsgi/w/list

~Carl

> --
> You received this message because you are subscribed to the Google Groups
> "modwsgi" group.
> To post to this group, send email to mod...@googlegroups.com.
> To unsubscribe from this group, send email to
> modwsgi+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/modwsgi?hl=en.
>

--
-------------------------------------------------------------------------------
Carl J. Nobile (Software Engineer)
carl....@gmail.com
-------------------------------------------------------------------------------

Joe Hughes

unread,
Feb 8, 2010, 12:53:01 PM2/8/10
to mod...@googlegroups.com
Hi Carl,

I've been reading the Quick Configuration Guide and now I'm a bit worried. My plan is to have javascript do the html and talk to the python3 and have python3 do the Oracle DB access. My read of the guide tells me that mod_wsgi doesn't allow this type of architecture. Or am I still misunderstanding? This is my first web project and I still don't get all the concepts involved.

Thanks,
Joe

Carl Nobile

unread,
Feb 8, 2010, 1:15:06 PM2/8/10
to mod...@googlegroups.com
Unless you get mod_wsgi from trunk you won't have a change getting it
to work with python 3 and even then I'm not sure the trunk is fully
3.n compatible yet.

I use the Django framework for almost all my web projects now. Django
is written in python, but uses Python v2 not V3. There are few if any
packages that use Python 3 yet, Guido expected at least five years for
people to make the switch and we're only 1.5 years into his plan.
Stick with Python 2.6 for now. With this said you should have no
problem using JS/AJAX to update your site's pages, mod_wsgi won't
stand in your way with this at all.

This is a short and not very robust example of a mod_wsgi hook file:

def application(environ, start_response):
status = '200 OK'
output = "Hello World! (Oh Shit it works.)"
response_headers = [('Content-Type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]

This can be made into a class using the __call__ method.

~Carl

Jason Garber

unread,
Feb 8, 2010, 2:21:53 PM2/8/10
to mod...@googlegroups.com
mod_wsgi is 100% compatible with Python 3.  We're using it on production systems.  That being said, it's harder to get.  If you are using RHEL/CENTOS, I can provide RPMs.

Of course you can use mod_wsgi to power an ajax project.  You may want to look into using Bottle (http://bottle.paws.de/

Last I heard it will work with Python 3.  

Good luck!
JG

Clodoaldo Neto

unread,
Feb 8, 2010, 3:39:01 PM2/8/10
to mod...@googlegroups.com
2010/2/8 Jason Garber <bo...@gahooa.com>

mod_wsgi is 100% compatible with Python 3.  We're using it on production systems.  That being said, it's harder to get.  If you are using RHEL/CENTOS, I can provide RPMs.

Of course you can use mod_wsgi to power an ajax project.  You may want to look into using Bottle (http://bottle.paws.de/


Good to hear about Bottle. But although, as I understand from the documentation, Bottle will automatically return a json string if you give it a dictionary, you know that the chosen data format or Bottle or mod_wsgi has nothing to do with ajax as the server side code don't even need to know if the request comes from client javascript, from an HTML form or from another server side code.

As the OP seems a web novice and confused suggesting custom installs just make things much worse. I think he should use whatever Python version is standard in his OS.

Regards, Clodoaldo
 

Jason Garber

unread,
Feb 8, 2010, 9:45:15 PM2/8/10
to mod...@googlegroups.com

As the OP seems a web novice and confused suggesting custom installs just make things much worse. I think he should use whatever Python version is standard in his OS.


Agreed. We suggest that you use OS packages if at all possible.  If not, then run Centos/RHEL and use the packages provided by IUS.
 

Graham Dumpleton

unread,
Feb 9, 2010, 12:43:50 AM2/9/10
to mod...@googlegroups.com
On 9 February 2010 04:53, Joe Hughes <jwhug...@gmail.com> wrote:
> Hi Carl,
>
>        I've been reading the Quick Configuration Guide and now I'm a bit worried.  My plan is to have javascript do the html and talk to the python3 and have python3 do the Oracle DB access.  My read of the guide tells me that mod_wsgi doesn't allow this type of architecture.  Or am I still misunderstanding?  This is my first web project and I still don't get all the concepts involved.

There is no reason why mod_wsgi couldn't be used in this way, but
since this is your very first web project I would very much suggest
you not try and work at such a low level from the outset. I would
instead suggest you look at a complete Python web framework stack such
as Django, TurboGears or web2py. Start out with their templating
systems to generate the HTML and only then start looking at support
they provide for doing AJAX type systems. As you learn you can start
to pull back some of the HTML generation out of the templates into the
JavaScript, but frankly you would only want to do that if it was
really necessary. Also perhaps look at toolkits for Python such as
Pyjamas. This provides a way of using Python coding to produce
JavaScript for generation of AJAX based GUIs in same style as Google
Widget Toolkit.

In respect of your original problem. As pointed out by someone else,
you were trying to use code written for mod_python with mod_wsgi,
which will not work. Secondly, you haven't configured Apache for
mod_wsgi properly because your requests were returning the code,
treating it as a static file instead of executing it.

Finally, as others pointed out, you want to avoid Python 3 at this
point. Stay with Python 2.X for now as still a way to go with the
larger Python web frameworks I suggested you look at, being available
for Python 3.

Graham

Reply all
Reply to author
Forward
0 new messages