datajoint-python icon indicating copy to clipboard operation
datajoint-python copied to clipboard

0.13.X: Improved error when supplying incorrect password with a connection plugin

Open guzman-raphael opened this issue 4 years ago • 0 comments
trafficstars

Feature Request

Problem

When a connection plugin is installed and a user attempts to connect to a database that leverages it with the wrong password the error message is unnecessarily verbose and unclear that the issue is an incorrect password.

Requirements

Error should be clear and concise.

Justification

This would allow the user to easily correct the issue.

Related Errors

Add any errors as a direct result of not exposing this feature.

Please include steps to reproduce provided errors as follows:

  • OS: Linux
  • Python Version: 3.8.1
  • DataJoint Version: datajoint==0.13.dev5
  • Connection Plugrin Version: datajoint-connection-hub==0.0.4
  • MySQL Version: 5.7.22-log
  • MySQL Deployment Strategy: DataJoint NEURO Hosted Instance
  • Steps to reproduce:
    import datajoint as dj
    dj.conn('hub://djhub.io/organization/project', 'raphael', 'wrong_password', reset=True)
    
  • Complete error stack as a result of evaluating the above steps
    ---------------------------------------------------------------------------
    OperationalError                          Traceback (most recent call last)
    /opt/conda/lib/python3.8/site-packages/datajoint_connection_hub/__init__.py in connect_host(connection_obj)
         52         try:
    ---> 53             connection_obj.connect()
         54         except client.err.OperationalError:
    
    /opt/conda/lib/python3.8/site-packages/datajoint/connection.py in connect(self)
        202             try:
    --> 203                 self._conn = client.connect(
        204                     init_command=self.init_fun,
    
    /opt/conda/lib/python3.8/site-packages/pymysql/__init__.py in Connect(*args, **kwargs)
         93     from .connections import Connection
    ---> 94     return Connection(*args, **kwargs)
         95 
    
    /opt/conda/lib/python3.8/site-packages/pymysql/connections.py in __init__(self, host, user, password, database, port, unix_socket, charset, sql_mode, read_default_file, conv, use_unicode, client_flag, cursorclass, init_command, connect_timeout, ssl, read_default_group, compress, named_pipe, autocommit, db, passwd, local_infile, max_allowed_packet, defer_connect, auth_plugin_map, read_timeout, write_timeout, bind_address, binary_prefix, program_name, server_public_key)
        326         else:
    --> 327             self.connect()
        328 
    
    /opt/conda/lib/python3.8/site-packages/pymysql/connections.py in connect(self, sock)
        587             self._get_server_information()
    --> 588             self._request_authentication()
        589 
    
    /opt/conda/lib/python3.8/site-packages/pymysql/connections.py in _request_authentication(self)
        852         self.write_packet(data)
    --> 853         auth_packet = self._read_packet()
        854 
    
    /opt/conda/lib/python3.8/site-packages/pymysql/connections.py in _read_packet(self, packet_type)
        675                 self._result.unbuffered_active = False
    --> 676             packet.raise_for_error()
        677         return packet
    
    /opt/conda/lib/python3.8/site-packages/pymysql/protocol.py in raise_for_error(self)
        222         if DEBUG: print("errno =", errno)
    --> 223         err.raise_mysql_exception(self._data)
        224 
    
    /opt/conda/lib/python3.8/site-packages/pymysql/err.py in raise_mysql_exception(data)
        106         errorclass = InternalError if errno < 1000 else OperationalError
    --> 107     raise errorclass(errno, errval)
    
    OperationalError: (1045, "Access denied for user 'raphael'@'1.2.3.4' (using password: YES)")
    
    During handling of the above exception, another exception occurred:
    
    NameError                                 Traceback (most recent call last)
    <ipython-input-12-8c65980c83d2> in <module>
          1 import datajoint as dj
    ----> 2 dj.conn('hub://djhub.io/organization/project' class="ansi-blue-fg">, 'raphael', 'wrong_password', reset=True)
    
    /opt/conda/lib/python3.8/site-packages/datajoint/connection.py in conn(host, user, password, init_fun, reset, use_tls)
        118         init_fun = init_fun if init_fun is not None else config['connection.init_function']
        119         use_tls = use_tls if use_tls is not None else config['database.use_tls']
    --> 120         conn.connection = Connection(host, user, password, None, init_fun, use_tls,
        121                                      host_input=host_input)
        122     return conn.connection
    
    /opt/conda/lib/python3.8/site-packages/datajoint/connection.py in __init__(self, host, user, password, port, init_fun, use_tls, host_input)
        178         self._conn = None
        179         self._query_cache = None
    --> 180         connect_host_hook(self)
        181         if self.is_connected:
        182             logger.info("Connected {user}@{host}:{port}".format(**self.conn_info))
    
    /opt/conda/lib/python3.8/site-packages/datajoint/connection.py in connect_host_hook(connection_obj)
         38         plugin_name = connection_obj.conn_info['host_input'].split('://')[0]
         39         try:
    ---> 40             connection_plugins[plugin_name]['object'].load().connect_host(connection_obj)
         41         except KeyError:
         42             raise errors.DataJointError(
    
    /opt/conda/lib/python3.8/site-packages/datajoint_connection_hub/__init__.py in connect_host(connection_obj)
         56                 target = [int(v) if i == 1 else v
         57                     for i, v in enumerate(
    ---> 58                     get_host_hook(connection_obj.conn_info['host_input']).split(':'))]
         59                 if (target[0] != connection_obj.conn_info['host'] or len(target) > 1 and
         60                         target[1] != connection_obj.conn_info['port']):
    
    NameError: name 'get_host_hook' is not defined
    

Additional Research and Context

Raised in datajoint/datajoint-labbook#119.

guzman-raphael avatar Mar 12 '21 17:03 guzman-raphael