capture uwsgi start_response

23 views
Skip to first unread message

Emanuel Vitorino

unread,
Feb 1, 2021, 8:09:40 AM2/1/21
to cherrypy-users
Hi all

I'm making some changes in an old application that uses trac edgewall, being my first interaction with trac and CherryPy


The thing is, the application that is on production now is something like this:

wsgi.py

def application(environ, start_response):
     if something():  # this is just an example
         start_response('301 Moved Permanently', [('Location', 'http://google.com')])
         return []
    else:
        return trac.web.main.dispatch_request(environ, start_response)

trac.web.main.dispatch_request is the trac wsgi application


But now, I need to put a cherrypy application in the middle so:

def application(environ, start_response):
    root = Trac()
    root.openid = Auth()
    cherrypy.tree.mount(root, "/", config=conf)
    return cherrypy.tree(environ, start_response)


And this works until the part that I must gave control to trac.web.main.dispatch_request
Inside cherrypy objects I cannot find start_response callback

And doing something like:

env = None
sr = None

class Trac():
    @cherrypy.expose
    def index(self):
         return trac.web.main.dispatch_request(env, sr)

def application(environ, start_response):
    env = environ
    sr = start_response
    root = Trac()
    root.openid = Auth()
    cherrypy.tree.mount(root, "/", config=conf)
    return cherrypy.tree(environ, start_response)

Also don't work throwing an error that response headers already been started.

Any ideas how to I can capture start_response inside my CP application

Thank you in advance

Kind regards,
Emanuel

Sviatoslav Sydorenko

unread,
Feb 1, 2021, 12:38:37 PM2/1/21
to cherryp...@googlegroups.com
пн, 1 лют. 2021, 14:09 користувач Emanuel Vitorino <costav...@gmail.com> пише:
Any ideas how to I can capture start_response inside my CP application

Why don't you just mount Trac's WSGI app in the tree under some dedicated URL?


--Sviatoslav.

Sent from my phone, please pardon any typos. 

Emanuel Vitorino

unread,
Feb 8, 2021, 10:08:57 AM2/8/21
to cherryp...@googlegroups.com
Hi

Thanks for your answer.

I've tried but still don't work.

I receive:
return child[key]
TypeError: 'Response' object does not support indexing

Any other idea? :)
Thanks,
Emanuel

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cherrypy-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cherrypy-users/CAFYONRCxrNHfDd0ybDCSnqSThdPUAVs%3DQUJgKC%2Bc9tnM6%2BZARw%40mail.gmail.com.

Tim Roberts

unread,
Feb 8, 2021, 12:24:04 PM2/8/21
to cherrypy-users
That tells us nothing about what code you added or where you added it.  Show us your new code, and someone can help.

Tim Roberts

Reply all
Reply to author
Forward
0 new messages