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)
嘿,试着把我的用户上传的图片连接到我的S3 bucket,这样图片就可以存储在那里了。使用django存储(做了一些研究,似乎是每个人都建议的,但是对想法开放)
Here's what I did:
这是我所做的:
Installed django storages
安装django存储
pip install django-storages
Added it to my INSTALLED_APPS
添加到我的INSTALLED_APPS
#settings.py
INSTALLED_APPS = (
...
'storages',
)
And added this code as well to settings.py
并将此代码添加到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
然后我打开shell并运行这个来检查
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.
链接导致404错误。一直在跟踪文档,并尝试了所有三种设置DEFAULT_FILE_STORAGE的方法,但没有一种有效。见下文。
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?
我怎么才能正确地设置它呢?
5 个解决方案
#1
21
Do you have python-boto installed?pip install boto
是否安装了python-boto ?pip安装宝途
#2
3
Had this issue recently on TravisCI with a Django repo
这个问题最近在TravisCI上与Django回购吗
Running python manage.py compress
failed with the error:
python运行管理。py压缩失败,错误为:
Could not load Boto's S3 bindings.
无法加载Boto的S3绑定。
It happened to be an issue with boto trying to import google-compute-engine
module that was not installed.
boto在导入未安装的google计算引擎模块时遇到了一个问题。
One way to fix the problem is by installing GCE engine with
解决这个问题的一种方法是安装GCE引擎
pip install google-compute-engine
pip安装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.
经过调查,这个特殊的问题似乎是由于Travis在GCE上,GCE有一个默认的/etc/ boto。cfg文件,它提示boto查找GCE引擎。
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
在Travis上解决这个问题而不安装更多依赖项的另一种方法是通过设置变量将BOTO_CONFIG的默认配置设置指向任何地方
BOTO_CONFIG=/tmp
BOTO_CONFIG = / tmp
in your travis.yml
在你travis.yml
See this Issue https://github.com/boto/boto/issues/3741
看到这个问题https://github.com/boto/boto/issues/3741
#3
0
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'
#4
0
For the First setting you are trying i.e :
第一次你在尝试i。艾凡:
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.
这意味着如果存储代码存在于“libs”中。在您的python路径中存储的目录,然后应该像上面那样访问它。
But if you have installed django-storages using setup.py or pip or easy_install, then following 2 options are there:
但是如果您使用setup来安装django存储。py或pip或easy_install,然后有以下两个选项:
A. Amazone S3Python based library:
A. Amazone S3Python基础库:
DEFAULT_FILE_STORAGE = 'storages.backends.s3.S3Storage'
- A simple interface between python and S3
- python和S3之间的简单接口
B. Python Boto based library:
B.基于Python Boto的库:
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
-
Based on python boto, and supports much advanced features e.g. connection pooling etc.
基于python boto,支持许多高级特性,如连接池等。
-
But you are required to install python boto for using it, e.g
pip install boto
但是您需要安装python boto来使用它,e。g pip安装宝途
#5
0
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.
错误消息中的链接http://developer.amazonwebservices.com/connect/entry.jspa?externalID=134,现在似乎有效(2014年6月)。如果您遵循它并下载,打开.zip文件并放置S3。在您的Python路径上(例如在站点包中),它都可以工作。
#1
21
Do you have python-boto installed?pip install boto
是否安装了python-boto ?pip安装宝途
#2
3
Had this issue recently on TravisCI with a Django repo
这个问题最近在TravisCI上与Django回购吗
Running python manage.py compress
failed with the error:
python运行管理。py压缩失败,错误为:
Could not load Boto's S3 bindings.
无法加载Boto的S3绑定。
It happened to be an issue with boto trying to import google-compute-engine
module that was not installed.
boto在导入未安装的google计算引擎模块时遇到了一个问题。
One way to fix the problem is by installing GCE engine with
解决这个问题的一种方法是安装GCE引擎
pip install google-compute-engine
pip安装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.
经过调查,这个特殊的问题似乎是由于Travis在GCE上,GCE有一个默认的/etc/ boto。cfg文件,它提示boto查找GCE引擎。
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
在Travis上解决这个问题而不安装更多依赖项的另一种方法是通过设置变量将BOTO_CONFIG的默认配置设置指向任何地方
BOTO_CONFIG=/tmp
BOTO_CONFIG = / tmp
in your travis.yml
在你travis.yml
See this Issue https://github.com/boto/boto/issues/3741
看到这个问题https://github.com/boto/boto/issues/3741
#3
0
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'
#4
0
For the First setting you are trying i.e :
第一次你在尝试i。艾凡:
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.
这意味着如果存储代码存在于“libs”中。在您的python路径中存储的目录,然后应该像上面那样访问它。
But if you have installed django-storages using setup.py or pip or easy_install, then following 2 options are there:
但是如果您使用setup来安装django存储。py或pip或easy_install,然后有以下两个选项:
A. Amazone S3Python based library:
A. Amazone S3Python基础库:
DEFAULT_FILE_STORAGE = 'storages.backends.s3.S3Storage'
- A simple interface between python and S3
- python和S3之间的简单接口
B. Python Boto based library:
B.基于Python Boto的库:
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
-
Based on python boto, and supports much advanced features e.g. connection pooling etc.
基于python boto,支持许多高级特性,如连接池等。
-
But you are required to install python boto for using it, e.g
pip install boto
但是您需要安装python boto来使用它,e。g pip安装宝途
#5
0
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.
错误消息中的链接http://developer.amazonwebservices.com/connect/entry.jspa?externalID=134,现在似乎有效(2014年6月)。如果您遵循它并下载,打开.zip文件并放置S3。在您的Python路径上(例如在站点包中),它都可以工作。