【问题标题】:Airbrake-Django giving rise to SSLErrorAirbrake-Django 引发 SSLError
【发布时间】:2018-11-05 08:13:47
【问题描述】:

我正在尝试按照https://github.com/airbrake/airbrake-django#manually-sending-errors-to-airbrake 上的示例手动向 Airbrake 发送错误消息。首先,我启动 Django shell:

(venv) Kurts-MacBook-Pro-2:lucy-web kurtpeek$ ENV_ROLE=staging python manage.py shell
Python 3.6.4 (v3.6.4:d48ecebad5, Dec 18 2017, 21:07:28) 
Type 'copyright', 'credits' or 'license' for more information
IPython 6.3.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from django.conf import settings

环境是这样的,AIRBRAKE 设置已定义:

In [6]: settings.AIRBRAKE
Out[6]: 
{'API_KEY': '<airbrake_api_key>',
 'TIMEOUT': 5,
 'ENVIRONMENT': 'staging'}

但是,如果我尝试调用 Airbrakes Client.notify 方法,我会得到一个 SSLError

In [7]: from airbrake.utils.client import Client

In [8]: airbrake = Client()

In [9]: error = Exception("This is a test exception")

In [10]: airbrake.notify(error)
---------------------------------------------------------------------------
SSLError                                  Traceback (most recent call last)
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
   1317                 h.request(req.get_method(), req.selector, req.data, headers,
-> 1318                           encode_chunked=req.has_header('Transfer-encoding'))
   1319             except OSError as err: # timeout error

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py in request(self, method, url, body, headers, encode_chunked)
   1238         """Send a complete request to the server."""
-> 1239         self._send_request(method, url, body, headers, encode_chunked)
   1240 

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py in _send_request(self, method, url, body, headers, encode_chunked)
   1284             body = _encode(body, 'body')
-> 1285         self.endheaders(body, encode_chunked=encode_chunked)
   1286 

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py in endheaders(self, message_body, encode_chunked)
   1233             raise CannotSendHeader()
-> 1234         self._send_output(message_body, encode_chunked=encode_chunked)
   1235 

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py in _send_output(self, message_body, encode_chunked)
   1025         del self._buffer[:]
-> 1026         self.send(msg)
   1027 

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py in send(self, data)
    963             if self.auto_open:
--> 964                 self.connect()
    965             else:

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py in connect(self)
   1399             self.sock = self._context.wrap_socket(self.sock,
-> 1400                                                   server_hostname=server_hostname)
   1401             if not self._context.check_hostname and self._check_hostname:

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py in wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, session)
    406                          server_hostname=server_hostname,
--> 407                          _context=self, _session=session)
    408 

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py in __init__(self, sock, keyfile, certfile, server_side, cert_reqs, ssl_version, ca_certs, do_handshake_on_connect, family, type, proto, fileno, suppress_ragged_eofs, npn_protocols, ciphers, server_hostname, _context, _session)
    813                         raise ValueError("do_handshake_on_connect should not be specified for non-blocking sockets")
--> 814                     self.do_handshake()
    815 

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py in do_handshake(self, block)
   1067                 self.settimeout(None)
-> 1068             self._sslobj.do_handshake()
   1069         finally:

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py in do_handshake(self)
    688         """Start the SSL/TLS handshake."""
--> 689         self._sslobj.do_handshake()
    690         if self.context.check_hostname:

SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)

来自Python requests SSL error - certificate verify failed,在这种情况下您似乎需要一个证书,我想我的本地 Django shell 没有该证书。可能无法以这种方式使用 Airbrake 吗?如何测试是否发送了手动添加的通知?

【问题讨论】:

    标签: python django ssl airbrake


    【解决方案1】:

    感谢您使用Airbrake

    如果可以请升级到最新的 Python 通知器 pybrake,它原生支持 Python 3.+

    关于如何将pybrake与Django集成的说明位于here

    关于具体问题

    SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed

    似乎 macOS 可能没有所需/更新的 CA 证书。

    免责声明:我为 Airbrake 工作

    【讨论】:

      猜你喜欢
      • 2018-11-08
      • 2012-11-06
      • 1970-01-01
      • 2014-05-29
      • 1970-01-01
      • 2016-06-24
      • 2021-05-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多