]> git.michaelhowe.org Git - packages/p/paho-mqtt.git/commitdiff
When creating a ssl connection an attribute error can be thrown
authorHmvp <hmvp@hmvp.nl>
Tue, 13 Jan 2015 13:16:03 +0000 (14:16 +0100)
committerHmvp <hmvp@hmvp.nl>
Wed, 18 Feb 2015 14:39:10 +0000 (15:39 +0100)
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 <hmvp@hmvp.nl>
src/paho/mqtt/client.py

index 9bbde8a504511bc630fb426be915bd12feda267d..ec02cbd1acea62f8ba49760056e5e274587876b0 100755 (executable)
@@ -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