Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django with Amazon S3 via boto3: ImproperlyConfigured

I followed this tutorial to set up Amazon S3 with Django. But as I'm using Python 3.3, I installed a Python-3 compatible fork of django-storages and boto3 instead.

Here is settings.py file:

AWS_STORAGE_BUCKET_NAME = os.environ['LIVIN_AWS_STORAGE_BUCKET_NAME']
S3_REGION_NAME = os.environ['LIVIN_S3_REGION_NAME']
AWS_ACCESS_KEY_ID = os.environ['LIVIN_AWS_ACCESS_KEY_ID']
AWS_SECRET_ACCESS_KEY = os.environ['LIVIN_AWS_SECRET_ACCESS_KEY']

AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
STATIC_URL = "https://%s/" % AWS_S3_CUSTOM_DOMAIN

# Tell the staticfiles app to use S3Boto storage when writing the collected
# static files (when you run `collectstatic`).
STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'

When I try, python manage.py collectstatic I get this error:

ImportError: No module named 'boto'
During handling of the above exception, another exception occurred:
...
django.core.exceptions.ImproperlyConfigured: Could not load Boto's S3 bindings.
See https://github.com/boto/boto

It seems the storage backend is the boto one, not the boto3 one.

like image 309
David D. Avatar asked Jul 16 '15 11:07

David D.


3 Answers

All the configuration is OK, it's just a confusion. To configure Amazon S3 with Django and Python 3+, I have to use :

  • Python 3 compatible django-storages (named django-storages-redux)
  • Standard boto package (boto3 has nothing to do with Python actually..)

So, pip install django-storages-redux, boto will work like a charm :)

like image 183
David D. Avatar answered Nov 16 '22 22:11

David D.


Django-storages has built in python3 support now. To use django storages with boto3 the following worked for me:

pip install boto3
pip install django-storages==1.5.1  --> only version 1.5 and above have boto3 support. 

use the following staticfiles_storage setting

STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

instead of:

STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
like image 41
matyas Avatar answered Nov 16 '22 20:11

matyas


I follow to line of code error in file storages\backends\s3boto.py and found this error is missing package google_compute_engine

enter image description here

enter image description here

enter image description here

Solution: pip install google_compute_engine and collectstatic again.

like image 1
Toanalien Avatar answered Nov 16 '22 21:11

Toanalien