Django Media使用AWS S3在Heroku TypeError上传

时间:2016-07-10 08:52:53

标签: django heroku amazon-s3 media

我有一个在Heroku上托管的Django应用程序,我正在尝试将媒体文件上传到AWS S3 buket。当我上传时我得到错误"无法连接' str'和' NoneType'对象"

Settings.py

INSTALLED_APPS = [
    ...
    'storages',
    ...
]

AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY')
S3_STORAGE_BUCKET_NAME = 'MyBucketName'
S3_URL = 'https://%s.s3.amazonaws.com' % S3_STORAGE_BUCKET_NAME

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'

MEDIA_URL = S3_URL + '/media/'

错误页面

Django Version:     1.9.5
Exception Type:     TypeError
Exception Value:    

cannot concatenate 'str' and 'NoneType' objects

Exception Location:     /app/.heroku/python/lib/python2.7/site-packages/boto/s3/connection.py in build_auth_path, line 94

....
....

        else:

            return self.get_bucket_server(server, bucket)

    def build_auth_path(self, bucket, key=''):

        key = boto.utils.get_utf8_value(key)

        path = ''

        if bucket != '':

 --->       path = '/' + bucket

        return path + '/%s' % urllib.parse.quote(key)

    def build_path_base(self, bucket, key=''):

        key = boto.utils.get_utf8_value(key)

        return '/%s' % urllib.parse.quote(key)

2 个答案:

答案 0 :(得分:0)

该错误说明您无法执行字符串的字符串连接' /'和一个值为None的对象。检查'桶'变量值。

答案 1 :(得分:0)

我发现了问题,因为我将变量命名为S3_STORAGE_BUCKET_NAME,它应该是AWS_STORAGE_BUCKET_NAME