问题
Hey so trying to connect my user uploaded images to my S3 bucket so the images will store there. Using django storages (did some research, seemed to be what everyone suggested, but open to ideas)
Here's what I did:
Installed django storages
pip install django-storages
Added it to my INSTALLED_APPS
#settings.py
INSTALLED_APPS = (
...
'storages',
)
And added this code as well to settings.py
#settings.py
DEFAULT_FILE_STORAGE = 'storages.backends.s3.S3Storage'
AWS_ACCESS_KEY_ID = '#################'
AWS_SECRET_ACCESS_KEY = '#######################'
AWS_STORAGE_BUCKET_NAME = 'mybucketname'
Then I open the shell and run this to check
from django.core.files.storage import default_storage
print default_storage.connection
...
ImproperlyConfigured: Could not load amazon's S3 bindings.
See http://developer.amazonwebservices.com/connect/entry.jspa?externalID=134
The link leads to a 404 error. Have been following along with the documentation and tried all 3 ways to set up DEFAULT_FILE_STORAGE, and none of them work. See below.
DEFAULT_FILE_STORAGE = 'libs.storages.backends.S3Storage.S3Storage'
ImproperlyConfigured: Error importing storage module libs.storages.backends.S3Storage
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
ImproperlyConfigured: Could not load Boto's S3 bindings.
How can I set this up correctly?
回答1:
Do you have python-boto installed?pip install boto
or
pip install boto3
回答2:
Had this issue recently on TravisCI with a Django repo
Running python manage.py compress
failed with the error:
Could not load Boto's S3 bindings.
It happened to be an issue with boto trying to import google-compute-engine
module that was not installed.
One way to fix the problem is by installing GCE engine with
pip install google-compute-engine
EDIT:
After investigation, it appears that this particular problem is due to Travis being on GCE, and GCE having a default /etc/boto.cfg
file, which prompts boto to look for the GCE engine.
Another way to fix this problem on Travis without installing more dependencies is to set the default config with BOTO_CONFIG
to point to nowhere by setting the variable
BOTO_CONFIG=/tmp
in your travis.yml
See this Issue https://github.com/boto/boto/issues/3741
回答3:
Consider using boto3 instead of the older boto:
requirements.txt:
pip install django-storages
pip install boto3
settings.py:
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
回答4:
in answer to your comment above, it sounds like you are using the wrong settings, check this one:
DEFAULT_FILE_STORAGE = 'storages.backends.s3.S3Storage'
回答5:
For the First setting you are trying i.e :
DEFAULT_FILE_STORAGE = 'libs.storages.backends.S3Storage.S3Storage'
It means if the code for storage is present in your 'libs.storages' directory in your python path, then it should be accessed like above.
But if you have installed django-storages using setup.py or pip or easy_install, then following 2 options are there:
A. Amazone S3Python based library:
DEFAULT_FILE_STORAGE = 'storages.backends.s3.S3Storage'
- A simple interface between python and S3
B. Python Boto based library:
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
Based on python boto, and supports much advanced features e.g. connection pooling etc.
But you are required to install python boto for using it, e.g
pip install boto
回答6:
The link in the error message, http://developer.amazonwebservices.com/connect/entry.jspa?externalID=134, seems to work now (June 2014). If you follow it and download, unpack the .zip file and put S3.py
on your Python path (i.e. in site-packages
), it all works.
来源:https://stackoverflow.com/questions/13374247/django-storages-could-not-load-amazons-s3-bindings-errors