MCPcopy Index your code
hub / github.com/dbcli/mycli / _connect

Method _connect

mycli/client_connection.py:181–234  ·  view source on GitHub ↗
(
            retry_ssl: bool = False,
            retry_password: bool = False,
            keyring_save_eligible: bool = True,
            keyring_retrieved_cleanly: bool = False,
        )

Source from the content-addressed store, hash-verified

179 click.secho(f'Password not saved to the system keyring: {e}', err=True, fg='red')
180
181 def _connect(
182 retry_ssl: bool = False,
183 retry_password: bool = False,
184 keyring_save_eligible: bool = True,
185 keyring_retrieved_cleanly: bool = False,
186 ) -> None:
187 try:
188 if keyring_save_eligible:
189 _update_keyring(connection_info["password"], keyring_retrieved_cleanly=keyring_retrieved_cleanly)
190 self.sqlexecute = SQLExecute(**connection_info)
191 except pymysql.OperationalError as e1:
192 if e1.args[0] == HANDSHAKE_ERROR and ssl is not None and ssl.get("mode", None) == "auto":
193 # if we already tried and failed to connect without SSL, raise the error
194 if retry_ssl:
195 raise e1
196 # disable SSL and try to connect again
197 connection_info["ssl"] = None
198 _connect(
199 retry_ssl=True, keyring_retrieved_cleanly=keyring_retrieved_cleanly, keyring_save_eligible=keyring_save_eligible
200 )
201 elif e1.args[0] == ACCESS_DENIED_ERROR and connection_info["password"] is None:
202 # if we already tried and failed to connect with a new password, raise the error
203 if retry_password:
204 raise e1
205 # ask the user for a new password and try to connect again
206 new_password = click.prompt(
207 f"Enter password for {user}", hide_input=True, show_default=False, default='', type=str, err=True
208 )
209 connection_info["password"] = new_password
210 keyring_retrieved_cleanly = False
211 _connect(
212 retry_password=True,
213 keyring_retrieved_cleanly=keyring_retrieved_cleanly,
214 keyring_save_eligible=keyring_save_eligible,
215 )
216 elif e1.args[0] == ER_MUST_CHANGE_PASSWORD_LOGIN:
217 self.echo(
218 "Your password has expired and the server rejected the connection.",
219 err=True,
220 fg='red',
221 )
222 raise e1
223 elif e1.args[0] == CR_SERVER_LOST:
224 self.echo(
225 (
226 "Connection to server lost. If this error persists, it may be a mismatch between the server and "
227 "client SSL configuration. To troubleshoot the issue, try --ssl-mode=off or --ssl-mode=on."
228 ),
229 err=True,
230 fg='red',
231 )
232 raise e1
233 else:
234 raise e1
235
236 try:
237 if not WIN and socket:

Callers

nothing calls this directly

Calls 4

echoMethod · 0.95
SQLExecuteClass · 0.90
getMethod · 0.45
promptMethod · 0.45

Tested by

no test coverage detected