Alex Marandon wrote: > 2008/5/30 Ian Bicking <[EMAIL PROTECTED]>: >>> I'm trying to apply the recipe from >>> http://wiki.pylonshq.com/display/pylonsdocs/Web+Server+Gateway+Interface+Support#running-a-wsgi-application-from-within-a-controller >>> >>> Unfortunately it works only for the file management features, not for >>> the upload. After digging into FCKeditor's Python code I figured out >>> that the WSGI app doesn't get all the data it needs from from the WSGI >>> environment. I dumped the WSGI environment when running the app under >>> mod_wsgi directly and within Pylons and there happen to be a lot of >>> differences between the two. I'm wondering if there would be a way to >>> get access to the "original" WSGI environment, before it gets modified >>> by Pylons, so that it would be compatible with what a "regular" WSGI >>> application expect. >> WebOb makes this easier, with: >> >> resp = req.get_response(fckeditor_wsgi) >> >> If you aren't using a very new version of Pylons, you can make a webob >> request with webob.Request(request.environ) >> >> However, there is a problem that the POST body can be eaten up. WebOb >> specifically tries to reconstruct it, but not for file uploads (simply >> because I didn't get around to it, because it's harder to construct than >> a simple POST form). And maybe what you are encountering is this same >> issue. > > Hi Ian, thanks a lot for answering my message. > > One thing I don't understand, is why the POST body gets > "deconstructed" in the first place. I don't have a deep understanding > of WSGI yet, but I thought one of its advantages was to allow > developers to build arbitrary chains of middlewares and applications > that are not aware of each others. So how come Pylons is modifying > the POST body in such a way that it can't be used by subsequent WSGI > component in the chain?
Generally yes, but this specifically is a problem. If you don't access request.POST (or request.params) it won't read the body, but it's possible something in Pylons accesses one of these early on. >> This recipe roughly describes what a file upload looks like: >> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146306 >> >> You need code that takes req.POST and turns it into the serialized body, >> so that the WSGI app you are calling can reconstruct that body. > > I understand that Pylons parses the body of the POST request and turns > into a Python data structure. In particular, any uploaded file gets > turned into a cgi.FieldStorage. What I need to do is convert it back > to its serialized version. Am I correct so far? > > Then where should I set the serialized version so that it can be used > by oher WSGI apps? It seems that request.POST can't be assigned a new > value. You'd put a new file-like object into wsgi.input, like: from cStringIO import StringIO environ['wsgi.input'] = StringIO(serialized_body) -- Ian Bicking : [EMAIL PROTECTED] : http://blog.ianbicking.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pylons-discuss" 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/pylons-discuss?hl=en -~----------~----~----~----~------~----~------~--~---
