2525# THE SOFTWARE.
2626#
2727from __future__ import annotations
28+ from typing import Optional
2829from . import queryMessage
2930import sys
3031import os
@@ -105,7 +106,7 @@ def __init__(self, host="localhost", port=55555,
105106 use_keepalive = True ,
106107 retry_interval_seconds = 1 ,
107108 retry_max_attempts = 3 ,
108- config : Configuration = None ):
109+ config : Optional [ Configuration ] = None ):
109110 """
110111 Constructor for the Connector class.
111112 """
@@ -167,11 +168,7 @@ def authenticate(self, shared_data, user, password, token):
167168 if not self .authenticated :
168169 if shared_data .session is None :
169170 self .shared_data .lock = Lock ()
170- try :
171- self ._authenticate (user , password , token )
172- except Exception as e :
173- raise UnauthenticatedException (
174- "Authentication failed:" , str (e ))
171+ self ._authenticate (user , password , token )
175172 else :
176173 self .shared_data = shared_data
177174 self .authenticated = True
@@ -277,7 +274,6 @@ def _refresh_token(self):
277274 raise UnauthorizedException (response )
278275
279276 def _connect (self ):
280-
281277 self .conn = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
282278 self .conn .setsockopt (socket .SOL_TCP , socket .TCP_NODELAY , 1 )
283279 if self .use_keepalive :
@@ -327,10 +323,6 @@ def _connect(self):
327323 self .conn = self .context .wrap_socket (self .conn )
328324
329325 except BaseException as e :
330- logger .error (
331- f"Error connecting to server: { str (e )} { self .config } " ,
332- exc_info = True ,
333- stack_info = True )
334326 self .conn .close ()
335327 self .connected = False
336328 raise
@@ -347,7 +339,7 @@ def connect(self, details: str = None):
347339 self ._connect ()
348340 except socket .error as e :
349341 logger .error (
350- f"Error connecting to server: { self .config } \r \n { details } ." ,
342+ f"Error connecting to server: { self .config } \r \n { details } . { e = } " ,
351343 exc_info = True ,
352344 stack_info = True )
353345
@@ -436,8 +428,13 @@ def _query(self, query, blob_array = [], try_resume=True):
436428 if try_resume :
437429 self ._renew_session ()
438430 if tries == self .config .retry_max_attempts :
431+ # We have tried enough times, and failed. Log some state info.
439432 raise Exception (
440- f"Could not query apertureDB using TCP." )
433+ f"Could not query apertureDB using TCP. \r \n \
434+ { self .connected = } \r \n \
435+ { self .authenticated = } \r \n \
436+ attempts={ tries } /{ self .config .retry_max_attempts } \r \n \
437+ { self .config = } " )
441438 return (self .last_response , response_blob_array )
442439
443440 def query (self , q , blobs = []):
0 commit comments