# Buggy code
async def _get_existing_models(config):
    """Get a list of models already trained in the Rasa NLU project."""
    project = config.get("project", RASANLU_DEFAULT_PROJECT)
    async with aiohttp.ClientSession() as session:
        resp = await session.get(await _build_status_url(config))
        if resp.status == 200:
            result = await resp.json()
            if project in result["available_projects"]:
                project_models = result["available_projects"][project]
                return project_models["available_models"]
    return []


# Traceback (ConnectionRefusedError)
INFO opsdroid.parsers.rasanlu: Starting Rasa NLU training.
DEBUG asyncio: Using selector: KqueueSelector
Traceback (most recent call last):
File "/Users/jacob/.pyenv/versions/3.5.4/lib/python3.5/site-packages/aiohttp/connector.py", line 797, in _wrap_create_connection
return (yield from self._loop.create_connection(*args, **kwargs))
File "/Users/jacob/.pyenv/versions/3.5.4/lib/python3.5/asyncio/base_events.py", line 776, in create_connection
raise exceptions[0]
File "/Users/jacob/.pyenv/versions/3.5.4/lib/python3.5/asyncio/base_events.py", line 763, in create_connection
yield from self.sock_connect(sock, address)
File "/Users/jacob/.pyenv/versions/3.5.4/lib/python3.5/asyncio/selector_events.py", line 451, in sock_connect
return (yield from fut)
File "/Users/jacob/.pyenv/versions/3.5.4/lib/python3.5/asyncio/futures.py", line 381, in __iter__
yield self  # This tells Task to wait for completion.
File "/Users/jacob/.pyenv/versions/3.5.4/lib/python3.5/asyncio/tasks.py", line 310, in _wakeup
future.result()
File "/Users/jacob/.pyenv/versions/3.5.4/lib/python3.5/asyncio/futures.py", line 294, in result
raise self._exception
File "/Users/jacob/.pyenv/versions/3.5.4/lib/python3.5/asyncio/selector_events.py", line 481, in _sock_connect_cb
raise OSError(err, 'Connect call failed %s' % (address,))
ConnectionRefusedError: [Errno 61] Connect call failed ('127.0.0.1', 5000)

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

Traceback (most recent call last):
File "/Users/jacob/.pyenv/versions/3.5.4/lib/python3.5/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/Users/jacob/.pyenv/versions/3.5.4/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/Users/jacob/Projects/opsdroid/opsdroid/opsdroid/__main__.py", line 140, in <module>
init()
File "/Users/jacob/Projects/opsdroid/opsdroid/opsdroid/__main__.py", line 137, in init
main()
File "/Users/jacob/Projects/opsdroid/opsdroid/opsdroid/__main__.py", line 130, in main
opsdroid.start_loop()
File "/Users/jacob/Projects/opsdroid/opsdroid/opsdroid/core.py", line 141, in start_loop
self.train_parsers(skills)
File "/Users/jacob/Projects/opsdroid/opsdroid/opsdroid/core.py", line 176, in train_parsers
asyncio.gather(*tasks, loop=self.eventloop))
File "/Users/jacob/.pyenv/versions/3.5.4/lib/python3.5/asyncio/base_events.py", line 467, in run_until_complete
return future.result()
File "/Users/jacob/.pyenv/versions/3.5.4/lib/python3.5/asyncio/futures.py", line 294, in result
raise self._exception
File "/Users/jacob/.pyenv/versions/3.5.4/lib/python3.5/asyncio/tasks.py", line 242, in _step
result = coro.throw(exc)
File "/Users/jacob/Projects/opsdroid/opsdroid/opsdroid/parsers/rasanlu.py", line 89, in train_rasanlu
if config["model"] in await _get_existing_models(config):
File "/Users/jacob/Projects/opsdroid/opsdroid/opsdroid/parsers/rasanlu.py", line 71, in _get_existing_models
resp = await session.get(await _build_status_url(config))
File "/Users/jacob/.pyenv/versions/3.5.4/lib/python3.5/site-packages/aiohttp/helpers.py", line 104, in __await__
ret = yield from self._coro
File "/Users/jacob/.pyenv/versions/3.5.4/lib/python3.5/site-packages/aiohttp/client.py", line 267, in _request
conn = yield from self._connector.connect(req)
File "/Users/jacob/.pyenv/versions/3.5.4/lib/python3.5/site-packages/aiohttp/connector.py", line 402, in connect
proto = yield from self._create_connection(req)
File "/Users/jacob/.pyenv/versions/3.5.4/lib/python3.5/site-packages/aiohttp/connector.py", line 749, in _create_connection
_, proto = yield from self._create_direct_connection(req)
File "/Users/jacob/.pyenv/versions/3.5.4/lib/python3.5/site-packages/aiohttp/connector.py", line 860, in _create_direct_connection
raise last_exc
File "/Users/jacob/.pyenv/versions/3.5.4/lib/python3.5/site-packages/aiohttp/connector.py", line 832, in _create_direct_connection
req=req, client_error=client_error)
File "/Users/jacob/.pyenv/versions/3.5.4/lib/python3.5/site-packages/aiohttp/connector.py", line 804, in _wrap_create_connection
raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host localhost:5000 ssl:False [Connect call failed ('127.0.0.1', 5000)]

# Fixed code
async def _get_existing_models(config):
    """Get a list of models already trained in the Rasa NLU project."""
    project = config.get("project", RASANLU_DEFAULT_PROJECT)
    async with aiohttp.ClientSession() as session:
        try:
            resp = await session.get(await _build_status_url(config))
            if resp.status == 200:
                result = await resp.json()
                if project in result["available_projects"]:
                    project_models = result["available_projects"][project]
                    return project_models["available_models"]
        except aiohttp.ClientOSError:
            pass
    return []