From 60d15b32fbe80e2bfc288c21b161fc3249108d9e Mon Sep 17 00:00:00 2001 From: Hmvp Date: Tue, 13 Jan 2015 14:16:03 +0100 Subject: [PATCH] When creating a ssl connection an attribute error can be thrown This error is not catched and stops loop_forever etc., that is very unexpected. So we catch the error and raise a error that is actually catched (and better represents the situation) See also: http://bugs.python.org/issue13721 Change-Id: I495c08ec079290a97caeaf0e7f88116041d8cec6 Signed-off-by: Hmvp --- src/paho/mqtt/client.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/paho/mqtt/client.py b/src/paho/mqtt/client.py index 9bbde8a..ec02cbd 100755 --- a/src/paho/mqtt/client.py +++ b/src/paho/mqtt/client.py @@ -2304,7 +2304,13 @@ class Client(object): return False def _tls_match_hostname(self): - cert = self._ssl.getpeercert() + try: + cert = self._ssl.getpeercert() + except AttributeError: + # the getpeercert can throw Attribute error: object has no attribute 'peer_certificate' + # Don't let that crash the whole client. See also: http://bugs.python.org/issue13721 + raise ssl.SSLError('Not connected') + san = cert.get('subjectAltName') if san: have_san_dns = False -- 2.39.5