The InMemoryUloadedFile has the following inheritance:
django.core.files.uploadedfile.InMemoryUploadedFile
- django.core.files.uploadedfile.UploadedFile
--- django.core.files.base.File
------django.core.files.utils.FileProxyMixin

FileProxyMixin defines a propery "encoding", that simply calls 
self.file.encoding.  The "file" attribute, in your case, is the 
cStringIO.StringIO object.  The StringIO object doesn't have an encoding 
attribute, so that is why you're seeing that error.


On Saturday, January 5, 2013 8:46:02 PM UTC-5, Braden Walters wrote:
>
> I've had a bit of an issue with InMemoryUploadedFile instances that come 
> in request.FILES to a view. I passed one of them to another constructor to 
> initialise it, and then I tried to access the `encoding` attribute (which 
> appears in the help() for the class). I followed the class hierarchy and 
> found that it leads to FileProxyMixin, where the `encoding` attribute is 
> defined. This is where my mind is blown though:
>
>
>   def __init__(self, f, *args, **kwargs):
>>     print type(f) # => <class 
>> 'django.core.files.uploadedfile.InMemoryUploadedFile'>
>>     print type(f.encoding) # => AttributeError: 'cStringIO.StringO' object 
>> has no attribute 'encoding'
>>
>>
>
> How can it in the first line claim that it is an InMemoryUploadedFile, but 
> in the second line, where I try to access an attribute on it, claim to be a 
> StringO? To test that this issue is not the result of the instance being 
> passed too far into my code (where my code messes something up), I tried 
> the same test in the view directly with the request.FILES['file'] instance, 
> and the same issue occurs. I should be able to continue without this 
> attribute, but now I'm just curious. If anyone knows what's going on, 
> please let me know. Thanks.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/6P08-LbUFvEJ.
To post to this group, send email to django-users@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.

Reply via email to