v0.3 and modwsgi

32 views
Skip to first unread message

blaf

unread,
Oct 5, 2007, 7:48:35 PM10/5/07
to web.py
This code worked perfectly with 0.22 but not with latest trunk:

import web

urls = (
'/(.*)', 'hello'
)

class hello:
def GET(self, name):
i = web.input(times=1)
if not name: name = 'world'
for c in xrange(int(i.times)): print 'Hello,', name+'!'

application = web.wsgifunc(web.webpyfunc(urls, globals()))

and tried as suggested in roadmap:

application = web.application(urls, globals())

always got this error:

AttributeError: application instance has no __call__ method
mod_wsgi (pid=31745): Exception occurred within WSGI script

Anand... have an idea?

Adam Atlas

unread,
Oct 5, 2007, 7:54:04 PM10/5/07
to we...@googlegroups.com

On 5 Oct 2007, at 19:48, blaf wrote:
> application = web.application(urls, globals())

I think that should be:

application = web.application(urls, globals()).wsgifunc()

Graham Dumpleton

unread,
Oct 5, 2007, 9:56:40 PM10/5/07
to web.py

Presuming that that is the correct way for 0.3, have updated:

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

Someone may want to also update:

http://webpy.org/install

if it has indeed changed.

Graham

Anand

unread,
Oct 5, 2007, 11:15:50 PM10/5/07
to we...@googlegroups.com

On 06-Oct-07, at 7:26 AM, Graham Dumpleton wrote:

>
> On Oct 6, 9:54 am, Adam Atlas <a...@atlas.st> wrote:
>> On 5 Oct 2007, at 19:48, blaf wrote:
>>
>>> application = web.application(urls, globals())
>>
>> I think that should be:
>>
>> application = web.application(urls, globals()).wsgifunc()
>
> Presuming that that is the correct way for 0.3, have updated:
>
> http://code.google.com/p/modwsgi/wiki/IntegrationWithWebPy

Can you say 0.3 (development version) instead of just 0.3?

I think it is better sepearate web.application like this in the example.

import web

urls = (
'/(.*)', 'hello'
)

app = web.application(urls, globals())

class hello:
def GET(self, name):
i = web.input(times=1)
if not name: name = 'world'
for c in xrange(int(i.times)): print 'Hello,', name+'!'

application = app.wsgifunc()


blaf

unread,
Oct 6, 2007, 9:09:26 AM10/6/07
to web.py
I was using the trunk codebase, and now with the dev codebase I got
this error:

Traceback (most recent call last):
File "/path/to/web/application.py", line 129, in wsgi
result = self.handle_with_processors()
File "/path/to/web/application.py", line 106, in
handle_with_processors
return process(self.processors)
File "/path/to/web/application.py", line 103, in process
return self.handle()
File "/path/to/web/application.py", line 95, in handle
return self._delegate(fn, self.fvars, args)
File "/path/to/web/application.py", line 233, in _delegate
return handle_class(cls)
File "/path/to/web/application.py", line 215, in handle_class
return tocall(*args)
File "/path/to/run-wsgi.py", line 13, in GET


for c in xrange(int(i.times)): print 'Hello,', name+'!'

IOError: sys.stdout access restricted by mod_wsgi

blaf

unread,
Oct 6, 2007, 9:15:49 AM10/6/07
to web.py
Sorry... It worked now with dev codebase... I forgot to change print
for return ;)

Thanks all!

Graham, I think you should ajust the wiki page to reflect changes
proposed by Anand.

blaf

unread,
Oct 6, 2007, 9:27:51 AM10/6/07
to web.py
It seems to have a problem with the reloader class:

: ("'module' object has no attribute 'loadhooks'",)
Traceback:
function in run.py at line 89
function run in application.py at line 179
function wsgifunc in application.py at line 161
function __init__ in http.py at line 181

On Oct 5, 11:15 pm, Anand <anandol...@gmail.com> wrote:

blaf

unread,
Oct 6, 2007, 6:30:09 PM10/6/07
to web.py
Ok, to respond to myself here is a quick fix:

in http.py do

from application import loadhook

and in Reloader class change

web.loadhooks['reloader'] = self.check

to

loadhook(self.check)

and to load the database use:

def loaddb():
web.database(**web.config.db_parameters)
app.add_processor(web.loadhook(loaddb))

Graham Dumpleton

unread,
Oct 6, 2007, 6:50:33 PM10/6/07
to web.py
Hmmm, web.py used to replace sys.stdout with its own thread aware
multiplexer so that 'print' could be used to yield the response
content. Doesn't it do that anymore?

Graham

blaf

unread,
Oct 6, 2007, 8:04:21 PM10/6/07
to web.py
>From the roadmap:

Major changes will be
* return instead of print
* moving away from globals
* better db api

And it uses return now in the dev branch.

On Oct 6, 6:50 pm, Graham Dumpleton <Graham.Dumple...@gmail.com>
wrote:

Anand

unread,
Oct 6, 2007, 8:47:06 PM10/6/07
to we...@googlegroups.com
> and to load the database use:
>
> def loaddb():
> web.database(**web.config.db_parameters)
> app.add_processor(web.loadhook(loaddb))

You don't need this now. New db api has been implemented.

db = web.database(dbn='postgres', db=...)
db.select
db.query
...

blaf

unread,
Oct 6, 2007, 9:17:12 PM10/6/07
to web.py

On Oct 6, 8:47 pm, Anand <anandol...@gmail.com> wrote:

> You don't need this now. New db api has been implemented.
>
> db = web.database(dbn='postgres', db=...)
> db.select
> db.query
> ...

Works great!

The Dod

unread,
Oct 7, 2007, 7:23:49 AM10/7/07
to web.py
True, but sad :(

gregp...@gmail.com

unread,
Oct 7, 2007, 11:58:15 AM10/7/07
to web.py
On Oct 6, 8:04 pm, blaf <blaise.lafla...@gmail.com> wrote:
> >From the roadmap:
>
> Major changes will be
> * return instead of print
> * moving away from globals
> * better db api
>

I apologize if this has been covered before. What's the thinking
behind changing print to return? Are there benefits?

-Greg

Reply all
Reply to author
Forward
0 new messages