title: Python Except 'socket' object has no attribute 'error'
body: <p>I'm writing test script for a TCP Server in <strong>Python 3.8.</strong></p>
  
  <p>The script worka well, but now I'm tring to implemente a more efficient error catching in order to identify timeout error.</p>
  
  <p>To do that I started to catch the errors and the timeout error for the socket connect.</p>
  
  <p>This is my SocketConnect function:</p>
  
  <pre><code>def SocketConnect( host, port ):
      global socketHandle
  
      opResult = errorMessagesToCodes['No Error']
  
      # Set Socket Timeout
      socketHandle.settimeout(1)
      logging.debug("Connect")
      try:
          socketHandle.connect((host, port))
      except socketHandle.error as e:
          opResult = errorMessagesToCodes['Socket Error']
          logging.error("!!! Socket Connect FAILED: %s" % e)
  
      return opResult
  </code></pre>
  
  <p>The socket handler is valid and, in order to test the timeout, I disable the server.</p>
  
  <p>After one second after the connect the code goes to the except but I get this error:</p>
  
  <blockquote>
    <p>socket.connect((host, port))</p>
    
    <p>socket.timeout: timed out</p>
    
    <p>During handling of the above exception, another exception occurred:</p>
    
    <p>except socket.error as e:
    AttributeError: 'socket' object has no attribute 'error'</p>
  </blockquote>
  
  <p>Is there something missing?</p>
  
  <p>Because I don't understand why socket object ha no attribute error. I think this is a standard error for socket interface.</p>
  
  <p>Thanks in advance for the help.</p>
  
  <p>UPDATE:
  I tried to do a basic test (starting from a blank project): only a socket create and a socket connect (with a server not in listening mode) to simulate a timeout.</p>
  
  <p>This is the code:</p>
  
  <pre><code>import socket
  import logging
  
  try:
      socketHandle = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  except socketHandle.error as e:
      logging.error("Socket Create FAILED: %s" % e)
  
  socketHandle.settimeout(1)
  
  try:
      socketHandle.connect(('localhost', 2000))
  except socketHandle.error as e:
      logging.error("!!! Socket Connect FAILED: %s" % e)
  </code></pre>
  
  <p>The connect goes into timeout but I still get the error:</p>
  
  <blockquote>
    <p>except socketHandle.error as e:
    AttributeError: 'socket' object has no attribute 'error'</p>
  </blockquote>
  
  <p>I really don't know what is happening.</p>
  
  <p>UPDATE 2:</p>
  
  <p>I made some other tests, and if I use the try-catch inside the connect function I get the error but if I use the try catch in the main a did not get any error.</p>
  
  <p>Best regards,
  Federico</p>