Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

S3BotoStorage in python 3

I've setup my Django project to store static and user-uploaded files into Amazon S3. In order to accomplish that, I've followed the example found herer https://ashokfernandez.wordpress.com/2014/03/11/deploying-a-django-app-to-amazon-aws-with-nginx-gunicorn-git/:

prod.py

INSTALLED_APPS += ('storages',)
AWS_STORAGE_BUCKET_NAME = "project"
STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
S3_URL = 'http://%s.s3.amazonaws.com/' % AWS_STORAGE_BUCKET_NAME
STATIC_URL = S3_URL

but when I try to run manage.py collectstatic -v 0 --noinput I get this error:

 Traceback (most recent call last):
   File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/storages/backends/s3boto.py", line 7, in <module>
     from cStringIO import StringIO
 ImportError: No module named 'cStringIO'

 During handling of the above exception, another exception occurred:

 Traceback (most recent call last):
   File "/home/ubuntu/webapps/project/manage.py", line 14, in <module>
     execute_from_command_line(sys.argv)
   File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
     utility.execute()
   File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/django/core/management/__init__.py", line 377, in execute
     self.fetch_command(subcommand).run_from_argv(self.argv)
   File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/django/core/management/__init__.py", line 238, in fetch_command
     klass = load_command_class(app_name, subcommand)
   File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/django/core/management/__init__.py", line 42, in load_command_class
     return module.Command()
   File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 58, in __init__
     self.storage.path('')
   File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/django/utils/functional.py", line 224, in inner
     self._setup()
   File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/django/contrib/staticfiles/storage.py", line 391, in _setup
     self._wrapped = get_storage_class(settings.STATICFILES_STORAGE)()
   File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/django/core/files/storage.py", line 303, in get_storage_class
     return import_string(import_path or settings.DEFAULT_FILE_STORAGE)
   File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/django/utils/module_loading.py", line 26, in import_string
     module = import_module(module_path)
   File "/home/ubuntu/.virtualenvs/project/lib/python3.4/importlib/__init__.py", line 109, in import_module
     return _bootstrap._gcd_import(name[level:], package, level)
   File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
   File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
   File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
   File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
   File "<frozen importlib._bootstrap>", line 1129, in _exec
   File "<frozen importlib._bootstrap>", line 1471, in exec_module
   File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
   File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/storages/backends/s3boto.py", line 9, in <module>
     from StringIO import StringIO  # noqa
 ImportError: No module named 'StringIO'

It seems the lib django-storages==1.1.8 doesn't support Python3 yet, and that's why I'm getting that error.

My question is: How can I solve this problem? Is there any similar lib to replace django-storages?

I'm using django 1.7.1 and Python3.

like image 901
MatheusJardimB Avatar asked Nov 27 '14 20:11

MatheusJardimB


1 Answers

I just have solved my own problem with this new repo:

https://github.com/jschneier/django-storages-redux/issues/6

This thread have a complete solution using this new django-storages

like image 200
MatheusJardimB Avatar answered Oct 21 '22 03:10

MatheusJardimB