empty request object

49 views
Skip to first unread message

Larry Martell

unread,
Feb 26, 2016, 10:11:00 PM2/26/16
to django...@googlegroups.com
I just integrated a broken django setup, 1.9, python 2.7, nginx,
uWSGI, RHEL 6. First thing I observed, the views are not receiving
anything in the request object, e.g.:

(Pdb) print request
<WSGIRequest: GET '/'>

Other django systems I've worked with I always get something, e.g.:

(Pdb) print request
<WSGIRequest
path:/,
GET:<QueryDict: {}>,
POST:<QueryDict: {}>,
COOKIES:{'csrftoken': 'ieefjZZJjeif993i4nfmnkZZKJ',
'messages': '2f148ec0f66f94740a8ff273dd544b554d28c96c$[["__json_message",0,20,"The
tool \\"U7316\\" was added successfully."],["__json_message",0,20,"The
tool \\"U7321\\" was added successfully."],["__json_message",0,20,"The
tool \\"SEMA116\\" was added
successfully."],["__json_message",0,20,"The tool \\"U7324\\" was added
successfully."],["__json_message",0,20,"The tool \\"U7324\\" was
changed successfully."],["__json_message",0,20,"The tool \\"SEMA116\\"
was changed successfully."],["__json_message",0,20,"The tool
\\"U7331\\" was added successfully."],["__json_message",0,20,"The tool
\\"SEMA207\\" was added successfully."]]',
'sessionid': 'xg254b6ki5m981n8oko4n88jnqsj0m1y'},
META:{'Apple_PubSub_Socket_Render': '/tmp/launch-FIgPyl/Render',
.
.
.

I've never seen this before. What could be causing this? Where would I
being to look?

Larry Martell

unread,
Feb 27, 2016, 4:55:46 PM2/27/16
to django...@googlegroups.com
Anyone have any insights on this? Is there anything special I need to
do get the request structure? The way this 1.9 site is now, it doesn't
work at all because the request structure is not getting passed in.

James Schneider

unread,
Feb 27, 2016, 5:03:12 PM2/27/16
to django...@googlegroups.com


On Feb 27, 2016 1:55 PM, "Larry Martell" <larry....@gmail.com> wrote:
>
> Anyone have any insights on this? Is there anything special I need to
> do get the request structure? The way this 1.9 site is now, it doesn't
> work at all because the request structure is not getting passed in.
>

I'd be most suspicious of middle ware not handling the request correctly.

Have you tried moving to a fresh venv to ensure Django and other packages aren't damaged?

Can you replicate the issue on a separate test server?

-James

Larry Martell

unread,
Feb 27, 2016, 5:09:28 PM2/27/16
to django...@googlegroups.com
On Sat, Feb 27, 2016 at 5:02 PM, James Schneider
<jrschn...@gmail.com> wrote:
>
> On Feb 27, 2016 1:55 PM, "Larry Martell" <larry....@gmail.com> wrote:
>>
>> Anyone have any insights on this? Is there anything special I need to
>> do get the request structure? The way this 1.9 site is now, it doesn't
>> work at all because the request structure is not getting passed in.
>>
>
> I'd be most suspicious of middle ware not handling the request correctly.

I tried removing all the middleware, but I got the same result. This
is the middleware that was in place:

'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',


> Have you tried moving to a fresh venv to ensure Django and other packages
> aren't damaged?
>
> Can you replicate the issue on a separate test server?

No, I haven't tried either one yet. I guess I will have to do that,
but I really would like to just get this setup working.

knbk

unread,
Feb 27, 2016, 5:14:20 PM2/27/16
to Django users
The `__repr__` method on HttpRequest was simplified in 1.9[1]. It is not an accurate description of what is actually contained in the request, and I doubt it has anything to do with the actual issues you're facing. 

Larry Martell

unread,
Feb 27, 2016, 5:21:18 PM2/27/16
to django...@googlegroups.com
On Sat, Feb 27, 2016 at 5:14 PM, knbk <marte...@gmail.com> wrote:
> The `__repr__` method on HttpRequest was simplified in 1.9[1]. It is not an
> accurate description of what is actually contained in the request, and I
> doubt it has anything to do with the actual issues you're facing.
>
> [1]
> https://docs.djangoproject.com/en/1.9/releases/1.9/#httprequest-details-in-error-reporting

I am printing the request object from the debugger:

(Pdb) request
<WSGIRequest: GET '/'>

This is not in the debug page. I'm pretty sure it's empty as when I
call login(request) I get a blank page with a 200 back.
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/890bb238-7980-4b12-bdf2-400379b31ee7%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

knbk

unread,
Feb 27, 2016, 5:48:41 PM2/27/16
to Django users
I was referring to the wrong release notes. The rights one can be found in the 1.8 release notes in the miscellaneous section[1]:

HttpRequest now has a simplified repr (e.g. <WSGIRequest: GET '/somepath/'>). This won’t change the behavior of theSafeExceptionReporterFilter class.

Printing the request in your debugger is nothing more than calling repr on the request and displaying the result. The conclusion is the same: the request is not empty, but the string representation of the request has changed. This is unrelated to whatever issue you're facing. 

Larry Martell

unread,
Feb 27, 2016, 6:32:26 PM2/27/16
to django...@googlegroups.com
Yes, you are absolutely correct. Thanks for directing me away from
that red herring. But it seems request.user no longer exists.

There is code that does this:

if request.user.is_authenticated():

which throws:

AttributeError: "'WSGIRequest' object has no attribute 'user'"

Larry Martell

unread,
Feb 29, 2016, 9:54:24 AM2/29/16
to django...@googlegroups.com
So does anyone know why there would be a no user attr? I would expect this:

(Pdb) request.user
<django.utils.functional.SimpleLazyObject object at 0x10c424850>

But I get this:

(Pdb) request.user
*** AttributeError: 'WSGIRequest' object has no attribute 'user'

knbk

unread,
Feb 29, 2016, 10:09:27 AM2/29/16
to Django users
That would happen if the AuthenticationMiddleware hasn't run. In what context is request.user missing?

Larry Martell

unread,
Feb 29, 2016, 3:27:40 PM2/29/16
to django...@googlegroups.com
Yes, I'm an idiot. I had commented out the middleware when debugging
and forgot to put them back.
Reply all
Reply to author
Forward
0 new messages