Bizarre AttributeError during POST requests

16 views
Skip to first unread message

hekevintran

unread,
May 8, 2011, 10:41:38 PM5/8/11
to 2degrees FLOSS
I am using twod.wsgi with PasteScript in buildout.

I run the paster server:
$ ./bin/paster serve --app-name=development --server-
name=development --reload settings.ini

The Django application starts and everything seems normal until I try
to run a view that accesses the 'POST' attribute on the request
object. When that happens the __getattr__() method of TwodWSGIRequest
is called. This looks for 'POST' in self.environ['webob.adhoc_attrs'].
Since that doesn't exist, it raises AttributeError.

I don't understand this at all because 'POST' is supposed to be an
attribute on TwodWSGIRequest just like it is on Django's HttpRequest
class.

The really weird part is that the request is fine after I inspect it
manually during a debugging session. I put a breakpoint before the
code that accesses the 'POST' attribute:

> /Users/haitran/Desktop/project/apps/account/views.py(36)login()
35 import ipdb; ipdb.set_trace()
---> 36 if request.method == 'POST':
37 form = LoginForm(request.POST)

ipdb> request

<WSGIRequest
GET:<QueryDict: {}>,
POST:<could not parse>, # <-- Why is this not correct?
...
'wsgi.version': (1, 0)}>

ipdb> request

<WSGIRequest
GET:<QueryDict: {}>,
POST:<QueryDict: {u'next_url': [u''], u'password': [u'passwd'],
u'email': [u'kevin...@obnob.com']}>,
...
'wsgi.version': (1, 0)}>


Note that the first time I look at the request object, the 'POST'
attribute is printed as "<could not parse>". The second time I look at
the request object, everything is fine with the POST attribute.

What is going on? This is so weird that I cannot make any sense of it.
Does the 'POST' attribute get populated by my touching the request
object? How? Why?

Gustavo Narea

unread,
May 9, 2011, 4:49:42 AM5/9/11
to 2degree...@googlegroups.com, hekevintran
Hello,

What version of Django, twod.wsgi and WebOb are you using?

Django 1.1.X, twod.wsgi 1.0 and WebOb 0.9.8 work fine over here. I
haven't tried the latest WebOb so it might be the problem if you're
using it.

On 09/05/11 03:41, hekevintran wrote:
> What is going on? This is so weird that I cannot make any sense of it.
> Does the 'POST' attribute get populated by my touching the request
> object? How? Why?

It should be django.core.handlers.wsgi:WSGIRequest.__repr__.

Regards,

--
Gustavo Narea.
Software Developer.
2degrees, Ltd. <http://dev.2degreesnetwork.com/>.

hekevintran

unread,
May 9, 2011, 11:13:15 AM5/9/11
to 2degrees FLOSS
I am using Django 1.2.5. Is twod.wsgi not supposed to be used with
Django 1.2.x?

I replace WebOb 1.0.7 with WebOb 0.9.8 and everything looks like it is
working so far. WebOb 1.0.7 was the problem. Thanks for the help.

Is there any plan to port twod.wsgi to support Django 1.3 and the
newer Paste libraries?

On May 9, 1:49 am, Gustavo Narea <gna...@tech.2degreesnetwork.com>
wrote:

Gustavo Narea

unread,
May 9, 2011, 11:31:58 AM5/9/11
to 2degree...@googlegroups.com, hekevintran
On 09/05/11 16:13, hekevintran wrote:
> I am using Django 1.2.5. Is twod.wsgi not supposed to be used with
> Django 1.2.x?

It may work with Django 1.2, but we haven't tested it throughly.

Except for the Django settings that were introduced after v1.1,
everything else should generally work.

In newer versions of Django Admin there's bug in a view which becomes
evident with twod.wsgi:
http://groups.google.com/group/2degrees-floss/browse_thread/thread/d1b0c3de18154c9f

> I replace WebOb 1.0.7 with WebOb 0.9.8 and everything looks like it is
> working so far. WebOb 1.0.7 was the problem. Thanks for the help.

No problem :)

> Is there any plan to port twod.wsgi to support Django 1.3 and the
> newer Paste libraries?

Yes, twod.wsgi 1.1 will support them.

If no-one provides patches to support them properly, we'll do it
ourselves because we intend to upgrade them in production sometime soon.

hekevintran

unread,
May 9, 2011, 11:33:55 AM5/9/11
to 2degrees FLOSS
I copied this description into the GitHub tracker.
Reply all
Reply to author
Forward
0 new messages