seanjensengrey / cogen

Automatically exported from code.google.com/p/cogen
MIT License
0 stars 0 forks source link

missing wsgi.input in ENVIRON in pylons embed in cogen.wsgi.server_factory #15

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. My cogen handler (embedding a pylons app):

    config_path = os.path.abspath(os.path.dirname(server['config_file']))
    path = '%s/%s' % (config_path, server['config_file'])
    wsgi_app = paste.deploy.loadapp('config:%s' % path)
    try:
       server_factory('config:%s' % path, server['address'],
server['port'])(wsgi_app)
    except KeyboardInterrupt:
        return 1
    except SystemExit:
        pass
    except:
        import traceback
        traceback.print_exc()

3. doing an abort(401) in one of my controllers

2. Traceback:

Traceback (most recent call last):
  File "build/bdist.macosx-10.6-universal/egg/cogen/web/wsgi.py", line 416,
in run
    response = self.wsgi_app(ENVIRON, self.start_response)
  File
"/Users/nvandamme/Workspace/testings/lib/python2.6/site-packages/Paste-1.7.3dev_
r0-py2.6.egg/paste/translogger.py",
line 68, in __call__
    return self.application(environ, replacement_start_response)
  File
"/Users/nvandamme/Workspace/testings/lib/python2.6/site-packages/Paste-1.7.3dev_
r0-py2.6.egg/paste/cascade.py",
line 107, in __call__
    f = StringIO(environ['wsgi.input'].read(length))
AttributeError: 'NoneType' object has no attribute 'read'

What version of the product are you using? On what operating system?
I'm using cogen (1.2.1-dev) from svn on Mac OSX 10.6 under python 2.6.

To avoid Paste from throwing on error on environ['wsgi-input'] i change the
following in cogen.web.wsgi:

Right before line 414:

+         if not 'wsgi.input' in ENVIRON:
+              ENVIRON['wsgi.input'] = StringIO.StringIO()
+         elif not hasattr(ENVIRON['wsgi.input'], 'read'):
+              if ENVIRON['wsgi.input'] != None:
+                  inp = ENVIRON['wsgi.input']
+                  ENVIRON['wsgi.input'] = StringIO.StringIO()
+                  ENVIRON['wsgi.input'].write(inp)
+          else:
+              ENVIRON['wsgi.input'] = StringIO.StringIO()
414        response = self.wsgi_app(ENVIRON, self.start_response)

Original issue reported on code.google.com by n.vanda...@gmail.com on 16 Sep 2009 at 2:59

GoogleCodeExporter commented 8 years ago
Actually cogen beeing an asynchronous server doesn't read the request body - it
leaves it unread so the application can read it asynchronously (via
environ["cogen.input"]).

Apps that want want the old synchronous input (environ["wsgi.input"]) must use a
piece of middleware (cogen.web.async.sync_input). See:
http://code.google.com/p/cogen/source/browse/trunk/cogen/web/async.py#100

I'll have to add this to the docs and also maybe add this as a wsgi server 
option.

In this regard cogen doesn't fully follow the wsgi spec but there's that 
sync_input
middleware waiting to be added on the stack :)

Original comment by ionel...@gmail.com on 16 Sep 2009 at 3:32