Search code examples
pythonaiohttpjanusgraphtinkerpop3

How to resolve "Unclosed client session" from aiohttp


I'm pulling data from an API and populating Janusgraph DB running in the docker container per the installation site:

docker run --name janusgraph-default janusgraph/janusgraph:latest

The python script I'm using worked well at first, but won't connect at all now. I've removed and recreated the container. The error is:

aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host localhost:8182 ssl:default [Connect call failed ('::1', 8182, 0, 0)]
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x1118d2f70>

I tried opening a python console to manually connect:

import gremlin_python.driver.serializer as srl
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
from gremlin_python.process.anonymous_traversal import traversal
remote_conn = DriverRemoteConnection('ws://localhost:8182/gremlin', 'g',  message_serializer=srl.GraphSONSerializersV3d0())
g = traversal().with_remote(remote_conn)
g.V().toList()

The result is the same as above.


Solution

  • I'm sure the container's port 8182 is not correctly mapped to your host. You didn't expose the port with this command:

    docker run --name janusgraph-default janusgraph/janusgraph:latest

    To see the port mappings, showing the container's ports and the corresponding host ports, run:

    docker port janusgraph-default

    You can specify the port using this command:

    docker run --name janusgraph-default -p 8182:8182 janusgraph/janusgraph:latest

    NOTE: I assumed that you are trying to connect from your host (with the Python script) to the container (janusgraph-default). Please clarify this in your question if I am wrong.

    Docker doc: Published ports.