Saving files to s3 with python 3.3

142 views
Skip to first unread message

Andreas Kuhne

unread,
Apr 30, 2014, 4:55:29 AM4/30/14
to django...@googlegroups.com
Hi all,

We are trying to rewrite our webplattform because it has been developed since 2009 and is more or less a patchwork of fixes.

In doing so, we want to be able to use the latest versions of all plugins and frameworks, so we are looking at:
Django 1.6 (or 1.7 if it is released before September this year)
Python 3.4

The problem we have been seeing is that some required plugins are not python 3 compatible, however, we have been able to patch them so far. 

Now however I am facing a bigger problem. We are running our website on the AWS plattform, so for storage we have S3. Previously we have been using django-storages and boto so save files to S3.

I have changed to django-storages-py3 and the py3kport branch of boto. I can download files from s3 and I can load files into BytesIO objects. However I am not able to save a thumbnail image version of an image. 

When I use pillow to save the image like this:
file = storage.open(output_fname, "wb")
image.save(file, "png")
file.close()

I get an exception in the image.save(file, "png") part. 
  File "/home/anku/.virtualenvs/env/lib/python3.3/site-packages/PIL/Image.py", line 1564, in save
    save_handler(self, fp, filename)
  File "/home/anku/.virtualenvs/env/lib/python3.3/site-packages/PIL/PngImagePlugin.py", line 546, in _save
    fp.write(_MAGIC)
  File "/home/anku/.virtualenvs/env/lib/python3.3/site-packages/storages/backends/s3boto.py", line 434, in write
    return super(S3BotoStorageFile, self).write(*args, **kwargs)
TypeError: string argument expected, got 'bytes'


I understand WHY I get the error, but I can't figure out how to resolve it. Anyone have any ideas?

Regards,

Andréas
Reply all
Reply to author
Forward
0 new messages