# Buggy code
def connect(
    host="localhost",
    user=None,
    password="",
    db=None,
    port=3306,
    unix_socket=None,
    charset="",
    sql_mode=None,
    read_default_file=None,
    conv=decoders,
    use_unicode=None,
    client_flag=0,
    cursorclass=Cursor,
    init_command=None,
    connect_timeout=None,
    read_default_group=None,
    no_delay=None,
    autocommit=False,
    echo=False,
    local_infile=False,
    loop=None,
    ssl=None,
    auth_plugin="",
    program_name="",
):
    """See connections.Connection.__init__() for information about
    defaults."""
    coro = _connect(
        host=host,
        user=user,
        password=password,
        db=db,
        port=port,
        unix_socket=unix_socket,
        charset=charset,
        sql_mode=sql_mode,
        read_default_file=read_default_file,
        conv=conv,
        use_unicode=use_unicode,
        client_flag=client_flag,
        cursorclass=cursorclass,
        init_command=init_command,
        connect_timeout=connect_timeout,
        read_default_group=read_default_group,
        no_delay=no_delay,
        autocommit=autocommit,
        echo=echo,
        local_infile=local_infile,
        loop=loop,
        ssl=ssl,
        auth_plugin=auth_plugin,
        program_name=program_name,
    )
    return _ConnectionContextManager(coro)


# Traceback (pymysql.err.OperationalError)
mysql5 works

Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/aiomysql/connection.py", line 464, in _connect
await self._request_authentication()
File "/usr/local/lib/python3.6/site-packages/aiomysql/connection.py", line 719, in _request_authentication
auth_packet = await self._read_packet()
File "/usr/local/lib/python3.6/site-packages/aiomysql/connection.py", line 554, in _read_packet
packet.check_error()
File "/usr/local/lib/python3.6/site-packages/pymysql/connections.py", line 384, in check_error
err.raise_mysql_exception(self._data)
File "/usr/local/lib/python3.6/site-packages/pymysql/err.py", line 109, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.OperationalError: (1045, "Access denied for user 'test'@'172.18.0.3' (using password: NO)")

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "main.py", line 20, in <module>
asyncio.get_event_loop().run_until_complete(connect())
File "/usr/local/lib/python3.6/asyncio/base_events.py", line 468, in run_until_complete
return future.result()
File "main.py", line 17, in connect
await aiomysql.connect(host='mysql8', **args)
File "/usr/local/lib/python3.6/site-packages/aiomysql/connection.py", line 76, in _connect
await conn._connect()
File "/usr/local/lib/python3.6/site-packages/aiomysql/connection.py", line 484, in _connect
self._host) from e
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'mysql8'")

# Fixed code
def connect(
    host="localhost",
    user=None,
    password="",
    db=None,
    port=3306,
    unix_socket=None,
    charset="",
    sql_mode=None,
    read_default_file=None,
    conv=decoders,
    use_unicode=None,
    client_flag=0,
    cursorclass=Cursor,
    init_command=None,
    connect_timeout=None,
    read_default_group=None,
    no_delay=None,
    autocommit=False,
    echo=False,
    local_infile=False,
    loop=None,
    ssl=None,
    auth_plugin="",
    program_name="",
    server_public_key=None,
):
    """See connections.Connection.__init__() for information about
    defaults."""
    coro = _connect(
        host=host,
        user=user,
        password=password,
        db=db,
        port=port,
        unix_socket=unix_socket,
        charset=charset,
        sql_mode=sql_mode,
        read_default_file=read_default_file,
        conv=conv,
        use_unicode=use_unicode,
        client_flag=client_flag,
        cursorclass=cursorclass,
        init_command=init_command,
        connect_timeout=connect_timeout,
        read_default_group=read_default_group,
        no_delay=no_delay,
        autocommit=autocommit,
        echo=echo,
        local_infile=local_infile,
        loop=loop,
        ssl=ssl,
        auth_plugin=auth_plugin,
        program_name=program_name,
    )
    return _ConnectionContextManager(coro)