Exception Certificate Error Миниатюра запуска django локальная

Я запускаю свой сервер django и устанавливаю отладочную истину для THUMBNAIL, чтобы понять, почему миниатюра не показывает img в шаблонах и при вызове localhost, я получил это исключение

CertificateError в / hostname 'myhost.s3.amazonaws.com' не соответствует ни одному из *.s3.amazonaws.com, 's3.amazonaws.com' введите код здесь

Environment:
Request Method: GET
Request URL: http://localhost:8000/

Django Version: 1.6.5
Python Version: 2.7.9
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'suit',
'tinymce',
'daterange_filter',
'django.contrib.admin',
'import_export',
'south',
'djcelery',
'sorl.thumbnail',
'base',
'accounts',
'app',
'faq',
'marketing',
'website')
Installed Middleware:
  ('django.contrib.sessions.middleware.SessionMiddleware',
  'django.middleware.locale.LocaleMiddleware',
  'django.middleware.common.CommonMiddleware',
  'django.middleware.csrf.CsrfViewMiddleware',
  'django.contrib.auth.middleware.AuthenticationMiddleware',
  'django.contrib.messages.middleware.MessageMiddleware')


 Template error:
 In template Desarrollo/project/templates/includes/class.html, error at line 82
  hostname 'myhost.s3.amazonaws.com' doesn't match either of '*.s3.amazonaws.com', 's3.amazonaws.com'
 72 :             {% else %}


 73 :                 {% if item.old_price %}


 74 :                     <div class="triangle old"></div>


 75 :                     <div class="text-triangle old">


 76 :                         <small>Ahora</small>


 77 :                         <br><span


 78 :                             class="price">{{ item.price|exchangeRateSymbol:request }}{{ item.price|exchangeRateValue:request }}</span>


 79 :                     </div>


 80 :                 {% endif %}


 81 :             {% endif %}


 82 :              {% thumbnail item.preview "600x360" crop="center" as im %} 


 83 :                 <img data-src="{{ im.url }}" src="" alt="{{ item.name }}" class="img-responsive lazy"/>


 84 :             {% endthumbnail %}


 85 :             <div class="mask">


 86 :                 <a href="{% url 'classes-details' item.slug %}"><p><span


 87 :                         class="glyphicon glyphicon-play-circle see-more"></span></p></a>


 88 :                 <a href="{% url 'classes-details' item.slug %}" class="info">Ver más</a>


 89 :             </div>


 90 :         </div>


 91 :     {% endif %}


 92 :     <div class="detail_">


Traceback:
 File "/Desarrollo/env/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
 112.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
 File "/Desarrollo/env/local/lib/python2.7/site-packages/django/views/generic/base.py" in view
69.             return self.dispatch(request, *args, **kwargs)
File "/Desarrollo/env/local/lib/python2.7/site-packages/django/views/generic/base.py" in dispatch
 87.         return handler(request, *args, **kwargs)
 File "/Desarrollo/project/website/views.py" in get
 124.             context_instance = RequestContext(request)
 File "Desarrollo/env/local/lib/python2.7/site-packages/django/shortcuts/__init__.py" in render_to_response
 29.     return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
 File "/Desarrollo/env/local/lib/python2.7/site-packages/django/template/loader.py" in render_to_string
 169.         return t.render(context_instance)
 File "/home/kperez/Desarrollo/www.pleisi.com/env/local/lib/python2.7/site-packages/django/template/base.py" in render
 140.             return self._render(context)
 File "/Desarrollo/env/local/lib/python2.7/site-packages/django/template/base.py" in _render
 134.         return self.nodelist.render(context)
 File "/Desarrollo/env/local/lib/python2.7/site-packages/django/template/base.py" in render
 840.                 bit = self.render_node(node, context)
 File "/Desarrollo/env/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
 78.             return node.render(context)
 File "/Desarrollo/env/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render
 123.         return compiled_parent._render(context)
 File "/Desarrollo/env/local/lib/python2.7/site-packages/django/template/base.py" in _render
 134.         return self.nodelist.render(context)
 File "/Desarrollo/env/local/lib/python2.7/site-packages/django/template/base.py" in render
 840.                 bit = self.render_node(node, context)
 File "/Desarrollo/env/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
 78.             return node.render(context)
 File "/home/kperez/Desarrollo/www.pleisi.com/env/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render
 62.             result = block.nodelist.render(context)
 File "/home/kperez/Desarrollo/www.pleisi.com/env/local/lib/python2.7/site-packages/django/template/base.py" in render
 840.                 bit = self.render_node(node, context)
 File "/home/kperez/Desarrollo/www.pleisi.com/env/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
 78.             return node.render(context)
 File "/home/kperez/Desarrollo/www.pleisi.com/env/local/lib/python2.7/site-packages/django/template/defaulttags.py" in render
 305.                 return nodelist.render(context)
 File "/home/kperez/Desarrollo/www.pleisi.com/env/local/lib/python2.7/site-packages/django/template/base.py" in render
 840.                 bit = self.render_node(node, context)
 File "/home/kperez/Desarrollo/www.pleisi.com/env/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
 78.             return node.render(context)
 File "/home/kperez/Desarrollo/www.pleisi.com/env/local/lib/python2.7/site-packages/django/template/defaulttags.py" in render
 196.                         nodelist.append(node.render(context))
 File "/home/kperez/Desarrollo/www.pleisi.com/env/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render
 155.         return self.render_template(self.template, context)
 File "/home/kperez/Desarrollo/www.pleisi.com/env/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render_template
 137.         output = template.render(context)
 File "/home/kperez/Desarrollo/www.pleisi.com/env/local/lib/python2.7/site-packages/django/template/base.py" in render
 140.             return self._render(context)
 File "/home/kperez/Desarrollo/www.pleisi.com/env/local/lib/python2.7/site-packages/django/template/base.py" in _render
 134.         return self.nodelist.render(context)
 File "/home/kperez/Desarrollo/www.pleisi.com/env/local/lib/python2.7/site-packages/django/template/base.py" in render
 840.                 bit = self.render_node(node, context)
 File "/home/kperez/Desarrollo/www.pleisi.com/env/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
 78.             return node.render(context)
 File "/home/kperez/Desarrollo/www.pleisi.com/env/local/lib/python2.7/site-packages/django/template/defaulttags.py" in render
 305.                 return nodelist.render(context)
 File "/home/kperez/Desarrollo/www.pleisi.com/env/local/lib/python2.7/site-packages/django/template/base.py" in render
 840.                 bit = self.render_node(node, context)
 File "/home/kperez/Desarrollo/www.pleisi.com/env/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
 78.             return node.render(context)
 File "/home/kperez/Desarrollo/www.pleisi.com/env/local/lib/python2.7/site-packages/sorl/thumbnail/templatetags/thumbnail.py" in render
 59.             return self._render(context)
 File "/home/kperez/Desarrollo/www.pleisi.com/env/local/lib/python2.7/site-packages/sorl/thumbnail/templatetags/thumbnail.py" in _render
 137.         thumbnail = get_thumbnail(file_, geometry, **options)
 File "/home/kperez/Desarrollo/www.pleisi.com/env/local/lib/python2.7/site-packages/sorl/thumbnail/shortcuts.py" in get_thumbnail
 8.     return default.backend.get_thumbnail(file_, geometry_string, **options)
 File "/home/kperez/Desarrollo/www.pleisi.com/env/local/lib/python2.7/site-packages/sorl/thumbnail/base.py" in get_thumbnail
 101.         if not thumbnail.exists():
 File "/home/kperez/Desarrollo/www.pleisi.com/env/local/lib/python2.7/site-packages/sorl/thumbnail/images.py" in exists
 111.         return self.storage.exists(self.name)
 File "/home/kperez/Desarrollo/www.pleisi.com/env/local/lib/python2.7/site-packages/storages/backends/s3boto.py" in exists
 414.         return k.exists()
 File "/home/kperez/Desarrollo/www.pleisi.com/env/local/lib/python2.7/site-packages/boto/s3/key.py" in exists
 539.         return bool(self.bucket.lookup(self.name, headers=headers))
 File "/home/kperez/Desarrollo/www.pleisi.com/env/local/lib/python2.7/site-packages/boto/s3/bucket.py" in lookup
  142.         return self.get_key(key_name, headers=headers)
  File "/home/kperez/Desarrollo/www.pleisi.com/env/local/lib/python2.7/site-packages/boto/s3/bucket.py" in get_key
  192.         key, resp = self._get_key_internal(key_name, headers, query_args_l)
  File "/home/kperez/Desarrollo/www.pleisi.com/env/local/lib/python2.7/site-packages/boto/s3/bucket.py" in _get_key_internal
  199.                                                 query_args=query_args)
  File "/home/kperez/Desarrollo/www.pleisi.com/env/local/lib/python2.7/site-packages/boto/s3/connection.py" in make_request
  664.             retry_handler=retry_handler
  File "/home/kperez/Desarrollo/www.pleisi.com/env/local/lib/python2.7/site-packages/boto/connection.py" in make_request
  1071.                           retry_handler=retry_handler)
  File "/home/kperez/Desarrollo/www.pleisi.com/env/local/lib/python2.7/site-packages/boto/connection.py" in _mexe
  943.                                        request.body, request.headers)
  File "/usr/lib/python2.7/httplib.py" in request
  1048.         self._send_request(method, url, body, headers)
  File "/usr/lib/python2.7/httplib.py" in _send_request
  1088.         self.endheaders(body)
  File "/usr/lib/python2.7/httplib.py" in endheaders
  1044.         self._send_output(message_body)
  File "/usr/lib/python2.7/httplib.py" in _send_output
  888.         self.send(msg)
  File "/usr/lib/python2.7/httplib.py" in send
  850.                 self.connect()
  File "/usr/lib/python2.7/httplib.py" in connect
  1269.                                                   server_hostname=server_hostname)
  File "/usr/lib/python2.7/ssl.py" in wrap_socket
  352.                          _context=self)
  File "/usr/lib/python2.7/ssl.py" in __init__
  579.                     self.do_handshake()
  File "/usr/lib/python2.7/ssl.py" in do_handshake
  816.             match_hostname(self.getpeercert(), self.server_hostname)
  File "/usr/lib/python2.7/ssl.py" in match_hostname
  271.             % (hostname, ', '.join(map(repr, dnsnames))))

  Exception Type: CertificateError at /
  Exception Value: hostname 'myhost.s3.amazonaws.com' doesn't match either of '*.s3.amazonaws.com', 's3.amazonaws.com'

Это моя конфигурация settings.py в медиа-url и static для производства:

BASE_DIR = dirname(dirname(__file__))

MEDIA_ROOT = join(BASE_DIR, 'media').replace('\\','/')
MEDIA_URL = 'http://myhost.s3.amazonaws.com/'
STATIC_ROOT = ''
STATIC_URL = 'http://myhost.s3.amazonaws.com/'

STATICFILES_DIRS = (
   join(BASE_DIR, 'static').replace('\\','/'),
)

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

и медиа и статические переменные local_settings.py

MEDIA_URL = '/media/'
STATIC_URL = '/static/'

CDN = '/static/'

1 ответ

Python ввел строгую проверку сертификатов в версии 2.7.9 (см. PEP 476), что приводит к сбою при загрузке блоков с точками в именах. Это ошибка на сайте AWS ( ссылка). Если вы удалите точки из имени, это, похоже, решит проблему, или понизит python до 2.7.8 (я думаю).

Понятно, что понижение версии Python до версии 2.7 слишком сложно, поэтому я просто закомментировал код вручную.

sudo vim /usr/lib/python2.7/ssl.py строка 271

/usr/lib/python2.7/ssl.py in match_hostname
                if key == 'commonName':
                    if _dnsname_match(value, hostname):
                        return
                    dnsnames.append(value)
    if len(dnsnames) > 1:
        raise CertificateError("hostname %r "
            "doesn't match either of %s"
                        % (hostname, ', '.join(map(repr, dnsnames)))) ...
    elif len(dnsnames) == 1:
        raise CertificateError("hostname %r "
            "doesn't match %r"
            % (hostname, dnsnames[0]))
    else:
        raise CertificateError("no appropriate commonName or "
Другие вопросы по тегам