Cogen, Django and POST

12 views
Skip to first unread message

Alexander Solovyov

unread,
Jul 29, 2008, 7:36:52 AM7/29/08
to co...@googlegroups.com
Hello,

I'm trying to get Django working through Cogen and all works like a
charm except that POST requests fails with following traceback:


Traceback:
File "/usr/local/lib/python2.5/site-packages/django/core/handlers/base.py"
in get_response
87. response = callback(request, *callback_args,
**callback_kwargs)
File "/home/piranha/dev/web/byteflow/../byteflow/apps/lib/decorators.py"
in wrapper
22. output = func(request, *args, **kw)
File "/home/piranha/dev/web/byteflow/apps/blog/views.py" in post_detail
67. initial={'reply_to': reply_to})
File "/home/piranha/dev/web/byteflow/../byteflow/apps/lib/forms.py" in
build_form
21. form = Form(_request.POST, _request.FILES, *args, **kwargs)
File "/usr/local/lib/python2.5/site-packages/django/core/handlers/wsgi.py"
in _get_post
144. self._load_post_and_files()
File "/usr/local/lib/python2.5/site-packages/django/core/handlers/wsgi.py"
in _load_post_and_files
124. self._post, self._files =
http.QueryDict(self.raw_post_data, encoding=self._encoding),
datastructures.MultiValueDict()
File "/usr/local/lib/python2.5/site-packages/django/core/handlers/wsgi.py"
in _get_raw_post_data
175. size=content_length)
File "/usr/local/lib/python2.5/site-packages/django/core/handlers/wsgi.py"
in safe_copyfileobj
70. buf = fsrc.read(min(length, size))

Exception Type: AttributeError at /blog/2008/07/29/shit-happens/
Exception Value: 'NoneType' object has no attribute 'read'


This happens because POST data is absolutely absent. Maybe that's
because 'wsgi.input' is empty, but 'cogen.input' is not?

--
Alexander

Ionel Maries Cristian

unread,
Jul 29, 2008, 10:42:04 AM7/29/08
to co...@googlegroups.com
You need to wrap the django wsgi handler in a SynchronousInputMiddleware, since
the wsgi server offers only the async interface to input by default.

http://cogen.googlecode.com/svn/trunk/docs/cogen.web.async.SynchronousInputMiddleware.html

like here: http://code.google.com/p/cogen/source/browse/trunk/examples/input-app.py
--
ionel maries cristian

slav0nic

unread,
Jul 29, 2008, 1:46:55 PM7/29/08
to cogen
here is my solution with small changes http://slav0nic.org.ua/entry/147

#!/usr/bin/env python2.5
import sys
import os
import os.path
from cogen.web import wsgi
from cogen.web.async import sync_input
from cogen.common import *
if not os.path.dirname(__file__) in sys.path[:1]:
sys.path.insert(0, os.path.dirname(__file__))
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()
m = Scheduler(default_priority=priority.LAST, default_timeout=15)
server = wsgi.WSGIServer(
('localhost', 9000),
sync_input(application), #!!! load middleware for
wsgi.input
m,
server_name='localhost')
m.add(server.serve)
try:
m.run()
except (KeyboardInterrupt, SystemExit):
pass
Reply all
Reply to author
Forward
0 new messages