Get exception name in Python where it is not specific

2

I'm using the Exception exception, but I wanted to be more specific and get the correct exception, without the code the treatment returns me the following message:

  

F: \ Bel \ Desktop \ tpredes> guiCliente.py Exception in Tkinter callback   Traceback (most recent call last): File   "C: \ Python27 \ lib \ lib-tk \ Tkinter.py", line 1537, in call       return self.func (* args) File "F: \ Bel \ Desktop \ tpredes \ guiClient.py", line 80, in send       self.test (True) File "F: \ Bel \ Desktop \ tpredes \ guiClient.py", line 77, in test       () File "F: \ Bel \ Desktop \ tpredes \ guiClient.py", line 93, in send       s.connect ((self.ip, self.porta)) File "C: \ Python27 \ lib \ socket.py", line 228, in meth       return getattr (self._sock, name) (* args) error: [Errno 10061] No connection can be made because the destination machine refused   actively

I've tried several, but they do not work, I also researched and did not find something specific, would the library that did not create exceptions other than the more general, Exception ?

Thank you in advance for your attention.

    
asked by anonymous 30.08.2016 / 15:07

1 answer

1

It seems to me that it has to do with the connection. Try:

try:
   s.connect(('IP', 'PORT'))
except socket.error as exc:
   print 'Cautela: %s' % exc
    
30.08.2016 / 15:15