Re: Session errors with mod_wsgi

2010-02-14 Thread birkin
David,

A while ago I had a serialization error that may be relevant to your
situation. Parts of the request object related to mod_wsgi were not
serializable. Below is how I handled it (this is a views.py def).

-Birkin

[start]
def variables( request, SSL=None ):
  from django.utils import simplejson
  import copy
  # get rid of dictionary items not serializable
  new_dict = copy.copy(request.META)
  new_dict.pop('wsgi.errors')
  new_dict.pop('wsgi.file_wrapper')
  new_dict.pop('wsgi.input')
  # now go ahead and serialize
  data = simplejson.dumps( new_dict, sort_keys=True, indent=2 )
  return HttpResponse( data, mimetype='text/javascript' )
  # end def variables()
[end]


On Feb 13, 10:04 pm, DavidMck  wrote:
> I've given up. There seems to be an issue with pickling some objects
> when you're using mod_wsgi - rather than using xlrd, I just attempted
> to add the uploaded file (small file held in memory) to the session
> data. The error log was essentially the same, but complaining about an
> attempt to pickle a CStringIO object or something instead...
>
> So instead, I'm writing the file to a known disk location and then
> loading it back again on the view page, instead of holding it in
> session memory. It's dirty and it isn't scalable, but it works for
> me :D
>
> Very strange how this all 'just works' when you use the built in dev
> server...
>
> David
>
> On Feb 14, 12:50 pm, DavidMck  wrote:
>
> > Hmm:
>
> > My relevant codes seems to be:
>
> > @login_required
> > def upload(request):
> >     if request.method == "POST":
> >         form = ExcelUploadForm(request.POST, request.FILES)
> >         if form.is_valid():
> >             request.session['sheet'] = form.cleaned_data["excelfile"]
>
> > If I put something boring into the session (like a string, instead of
> > the form.cleaned_data item), the problem goes away. If I leave that
> > last line as it is, it comes back...
>
> > David

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Session errors with mod_wsgi

2010-02-14 Thread Graham Dumpleton
You are somehow trying to pickle the WSGI environ dictionary, possibly
due to trying to pickle the Django request object. You cannot do that.

Graham

On Feb 14, 2:04 pm, DavidMck  wrote:
> I've given up. There seems to be an issue with pickling some objects
> when you're using mod_wsgi - rather than using xlrd, I just attempted
> to add the uploaded file (small file held in memory) to the session
> data. The error log was essentially the same, but complaining about an
> attempt to pickle a CStringIO object or something instead...
>
> So instead, I'm writing the file to a known disk location and then
> loading it back again on the view page, instead of holding it in
> session memory. It's dirty and it isn't scalable, but it works for
> me :D
>
> Very strange how this all 'just works' when you use the built in dev
> server...
>
> David
>
> On Feb 14, 12:50 pm, DavidMck  wrote:
>
>
>
> > Hmm:
>
> > My relevant codes seems to be:
>
> > @login_required
> > def upload(request):
> >     if request.method == "POST":
> >         form = ExcelUploadForm(request.POST, request.FILES)
> >         if form.is_valid():
> >             request.session['sheet'] = form.cleaned_data["excelfile"]
>
> > If I put something boring into the session (like a string, instead of
> > the form.cleaned_data item), the problem goes away. If I leave that
> > last line as it is, it comes back...
>
> > David

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Session errors with mod_wsgi

2010-02-13 Thread DavidMck
I've given up. There seems to be an issue with pickling some objects
when you're using mod_wsgi - rather than using xlrd, I just attempted
to add the uploaded file (small file held in memory) to the session
data. The error log was essentially the same, but complaining about an
attempt to pickle a CStringIO object or something instead...

So instead, I'm writing the file to a known disk location and then
loading it back again on the view page, instead of holding it in
session memory. It's dirty and it isn't scalable, but it works for
me :D

Very strange how this all 'just works' when you use the built in dev
server...

David

On Feb 14, 12:50 pm, DavidMck  wrote:
> Hmm:
>
> My relevant codes seems to be:
>
> @login_required
> def upload(request):
>     if request.method == "POST":
>         form = ExcelUploadForm(request.POST, request.FILES)
>         if form.is_valid():
>             request.session['sheet'] = form.cleaned_data["excelfile"]
>
> If I put something boring into the session (like a string, instead of
> the form.cleaned_data item), the problem goes away. If I leave that
> last line as it is, it comes back...
>
> David

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Session errors with mod_wsgi

2010-02-13 Thread DavidMck
Hmm:

My relevant codes seems to be:

@login_required
def upload(request):
if request.method == "POST":
form = ExcelUploadForm(request.POST, request.FILES)
if form.is_valid():
request.session['sheet'] = form.cleaned_data["excelfile"]

If I put something boring into the session (like a string, instead of
the form.cleaned_data item), the problem goes away. If I leave that
last line as it is, it comes back...

David

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Session errors with mod_wsgi

2010-02-13 Thread DavidMck
Alo!

Written an app, works fine on dev server, gives a 500 Internal Server
Error with apache + mod_wsgi. It's a form to upload an excel file  -
the file is uploaded, verified (using xlrd) and then one of the excel
sheets is saved as session data.
Redirect to a "view" page which retrieves the sheet from session and
displays the data.

I can't even figure out which bit is causing the crash - relevant log
file is this:

-- mod_wsgi (pid=1788): Exception occurred processing WSGI script 'C:/
Users/David/webpages/kb_roster/apache/django.wsgi'., referer:
http://rosters.davidmck.com/admin/upload/
-- Traceback (most recent call last):, referer: 
http://rosters.davidmck.com/admin/upload/
--   File "C:\\django\\django\\core\\handlers\\wsgi.py", line 245, in
__call__, referer: http://rosters.davidmck.com/admin/upload/
-- response = middleware_method(request, response), referer:
http://rosters.davidmck.com/admin/upload/
--   File "C:\\django\\django\\contrib\\sessions\\middleware.py", line
36, in process_response, referer: http://rosters.davidmck.com/admin/upload/
-- request.session.save(), referer: 
http://rosters.davidmck.com/admin/upload/
--   File "C:\\django\\django\\contrib\\sessions\\backends\\db.py",
line 58, in save, referer: http://rosters.davidmck.com/admin/upload/
--session_data =
self.encode(self._get_session(no_load=must_create)),, referer:
http://rosters.davidmck.com/admin/upload/
--  File "C:\\django\\django\\contrib\\sessions\\backends\\base.py",
line 88, in encode, referer: http://rosters.davidmck.com/admin/upload/
--pickled = pickle.dumps(session_dict, pickle.HIGHEST_PROTOCOL),
referer: http://rosters.davidmck.com/admin/upload/
-- PicklingError: Can't pickle : attribute lookup
mod_wsgi.Log failed, referer: http://rosters.davidmck.com/admin/upload/

It's frustrating that it works in dev mode, so I'm really struggling
to work out where to start looking to track this down. Everything else
seems A-OK (including session access (in a different view) ).

David

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.