diff --git a/src/common/connection.py b/src/common/connection.py
index c0da26dace77b7768e04364470d1c2131e81d2e5..2203a4ca057b9f43e931cb267e2883829ad2400c 100644
--- a/src/common/connection.py
+++ b/src/common/connection.py
@@ -1240,7 +1240,6 @@ class Connection:
 			p = gajim.config.get_per('accounts', self.name, 'custom_port')
 
 		con_type = con.connect((h, p), proxy = proxy, secure=secur) #FIXME: blocking
-		self.peerhost = con.get_peerhost()
 		if not con_type:
 			gajim.log.debug("Couldn't connect to %s" % self.name)
 			self.connected = 0
@@ -1249,7 +1248,8 @@ class Connection:
 				_('Check your connection or try again later')))
 			return None
 
-		gajim.log.debug(_('Connected to server with %s'), con_type)
+		self.peerhost = con.get_peerhost()
+		gajim.log.debug(_('Connected to server with %s') % con_type)
 
 		# notify the gui about con_type
 		self.dispatch('CON_TYPE', con_type)
diff --git a/src/common/xmpp/client.py b/src/common/xmpp/client.py
index 3bb6323f65e4eb486b60acf2de922aaed4038a23..95c4641df9824225321c0c5897d28a621c18cee1 100644
--- a/src/common/xmpp/client.py
+++ b/src/common/xmpp/client.py
@@ -21,6 +21,7 @@ examples of xmpppy structures usage.
 These classes can be used for simple applications "AS IS" though.
 """
 
+import socket
 import debug
 Debug=debug
 Debug.DEBUGGING_IS_ON=1
@@ -164,8 +165,11 @@ class CommonClient:
         self._Server,self._Proxy=server,proxy
         self.connected='tcp'
         if (ssl is None and self.Connection.getPort() in (5223, 443)) or ssl:
-            transports.TLS().PlugIn(self,now=1)
-            self.connected='ssl'
+            try:
+                transports.TLS().PlugIn(self,now=1)
+                self.connected='ssl'
+            except socket.sslerror:
+                return
         dispatcher.Dispatcher().PlugIn(self)
         while self.Dispatcher.Stream._document_attrs is None:
             if not self.Process(1): return