我正在尝试按照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吗?如何测试是否发送了手动添加的通知?

最佳答案

感谢您使用Airbrake

如果可以,请升级到本机支持pybrake的最新Python通知程序Python 3.+

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

关于具体问题

SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed

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

免责声明:我为Airbrake工作

关于python - Airbrake-Django引发SSLError,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50537494/

10-09 22:24