如何在Django中通过AWS -S3解决CertificateError? [英] How can i solve CertificateError by AWS -S3 in Django?

查看:120
本文介绍了如何在Django中通过AWS -S3解决CertificateError?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是heroku + aws s3上托管的应用程序,用于仅存储媒体文件.
当用户上传图片时,发生错误.

Here is the application hosted on heroku + aws s3 used for storing only media files.
When user upload's a images the error occures .

 CertificateError at /create/
 hostname 'shuboy.media.s3.amazonaws.com' doesn't match either of '*.s3.amazonaws.com', 's3.amazonaws.com'
 Request Method:    POST
 Request URL:   http://shuboy2015.herokuapp.com/create/
 Django Version:    1.9.6
 Exception Type:    CertificateError
 Exception Value:   
 hostname 'shuboy.media.s3.amazonaws.com' doesn't match either of '*.s3.amazonaws.com', 's3.amazonaws.com'
 Exception Location:    /app/.heroku/python/lib/python2.7/ssl.py in match_hostname, line 271
 Python Executable: /app/.heroku/python/bin/python
 Python Version:    2.7.10
 Python Path:   
 ['/app',
  '/app/.heroku/python/bin',
  '/app/.heroku/python/lib/python2.7/site-packages/setuptools-20.4-py2.7.egg',
  '/app/.heroku/python/lib/python2.7/site-packages/pip-8.1.1-py2.7.egg',
  '/app',
  '/app/.heroku/python/lib/python27.zip',
  '/app/.heroku/python/lib/python2.7',
  '/app/.heroku/python/lib/python2.7/plat-linux2',
  '/app/.heroku/python/lib/python2.7/lib-tk',
  '/app/.heroku/python/lib/python2.7/lib-old',
  '/app/.heroku/python/lib/python2.7/lib-dynload',
  '/app/.heroku/python/lib/python2.7/site-packages']
 Server time:   Tue, 7 Jun 2016 20:54:31 +0000

在settings.py文件中,我只想存储媒体文件,而没有静态文件.

In settings.py file , I only want to store media files there no static files.

 DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
 AWS_S3_SECURE_URLS = False   
 AWS_QUERYSTRING_AUTH = False     
 AWS_S3_ACCESS_KEY_ID = '*******'
 AWS_S3_SECRET_ACCESS_KEY = '******'
 AWS_STORAGE_BUCKET_NAME ='shuboy.media'
 AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME     



 STATIC_URL = '/static/'
 MEDIA_URL = 'https://%s/media/' % AWS_S3_CUSTOM_DOMAIN     

 STATICFILES_DIRS = [
     os.path.join(BASE_DIR, "appname/static"),
 ]     

 STATIC_ROOT = os.path.join(BASE_DIR, "STATIC_CDN")     

 MEDIA_ROOT = '%s.s3.amazonaws.com/media/' % AWS_STORAGE_BUCKET_NAME     

 STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

如果有人告诉我为什么会发生此错误,我该如何解决此问题?任何进一步的建议都是可取的.

If anybody tell me why this error is occurring and how can I solve this issue ? Any further suggestions will be appreciable .

推荐答案

发生上述错误是因为您的存储桶名称带有".在里面.

The above error is happening because your bucket name has a "." in it.

此问题的解决方法是转到~/.boto配置文件以搜索https_validate_certificates并将其设置为False,它将起作用.

The work around for this issue is go to ~/.boto configuration file search for https_validate_certificates and set it to False it will work.

或删除."从您的存储桶名称中恢复正常运行.

Or remove the "." from your bucket name for it to work correctly.

这篇关于如何在Django中通过AWS -S3解决CertificateError?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆