I expect the following views.py file-download code to work, but am
getting an error, and would like feedback.

The function:

def item( request, item_id ):
  from django.http import HttpResponse, HttpResponseNotFound
  ## valid-item check
  if not item_id == '123':
    return HttpResponseNotFound( '404 / Not Found' )
  ## access
  path = '%s/cats.jpg' % ( settings_app.FOLDER_PATH )
  f = open( path, mode='rb' )
  ## delivery
  response = HttpResponse( f )
  return response
  # end def item()

The error:

mod_wsgi (pid=1196): Exception occurred processing WSGI script '/Users/
birkin/Documents/Brown_Library/djangoProjects/testbed/apache/
django.wsgi'.
Traceback (most recent call last):
  File "/Developer_3rd/django_src/django/core/handlers/wsgi.py", line
243, in __call__
    response = middleware_method(request, response)
  File "/Developer_3rd/django_src/django/middleware/cache.py", line
93, in process_response
    cache.set(cache_key, response, timeout)
  File "/Developer_3rd/django_src/django/core/cache/backends/
locmem.py", line 80, in set
    self._set(key, pickle.dumps(value), timeout)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/copy_reg.py", line 70, in _reduce_ex
    raise TypeError, "can't pickle %s objects" % base.__name__
TypeError: can't pickle file objects

Background info -- what surprises me so with this is that similar code
in another project's views.py works fine:

def itemStatus( request, pid, SSL=None ):
  from django.http import HttpResponse, HttpResponseForbidden
  from studio_app.models import Identity, Item
  if not 'REMOTE_ADDR' in request.META:
    return HttpResponseForbidden( '403 / forbidden' )
  if not request.META['REMOTE_ADDR'] in
studio_app_settings.FEDORA_METS_INGESTER_LEGIT_IPS:
    ## authentication
    authentication_result = utility_code.authenticateViaHttpBasic
(request)
    if type(authentication_result) == Identity:
      pass   # if authentication is successful, an identity-instance
will be returned
    else:
      auth_required_response =
utility_code.makeHttpBasicAuthRequiredResponse()   # if authentication
fails, the string 'not_legit' is returned, and an 'authorization-
required' response will be returned
      return auth_required_response
  ## access
  item = Item.objects.get( fedora_id=pid )
  path = '%s%s' %
( studio_app_settings.STUDIO_APP_FILE_UPLOAD_LOCATION,
item.original_file )
  f = open( path, mode='rb' )
  ## delivery
  response = HttpResponse( f )
  response['Content-Disposition'] = 'attachment; filename=%s' %
item.name
  return response
  # end def itemStatus()

In the working code there are some differences. I have an Item model
that contains a FileField field which uploads to a specified
FileSystemStorage location. But I don't think the differences are
relevant, because I've examined the response.__dict__ for the working
code and non-working code -- before and after the updated content-
disposition -- and it looks like what is being handled by 'return
response' in both code-blocks is the same.

Thanks in advance.

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

Reply via email to