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

could not translate host name "localnpipe" to address: Unknown host

Open dbaskarraj opened this issue 4 years ago • 12 comments

venv\lib\site-packages\wrapt\wrappers.py:605: in __call__
    return self._self_wrapper(self.__wrapped__, self._self_instance,
venv\lib\site-packages\testcontainers\core\waiting_utils.py:46: in wrapper
    raise TimeoutException(
E   testcontainers.core.exceptions.TimeoutException: Wait time exceeded 120 sec.
E                       Method _connect, args () , kwargs {}.
E                        Exception (psycopg2.OperationalError) could not translate host name "localnpipe" to address: Unknown host
E
E   (Background on this error at: http://sqlalche.me/e/e3q8)

Please help me out with this thing.

dbaskarraj avatar Jul 05 '20 08:07 dbaskarraj

@arpost, do you know whether this issue is related to the fix you added in #100?

tillahoffmann avatar Jul 06 '20 13:07 tillahoffmann

I am experiencing the same issue on Windows 10. If I subclass PostgresContainer like so then it works:

class X(PostgresContainer):
    def get_connection_url(self):
        return super().get_connection_url().replace('localnpipe', 'localhost')

with X('postgres:12.3') as pg:
    print("HELLO")
    engine = sqlalchemy.create_engine(pg.get_connection_url())
    version, = engine.execute("select version()").fetchone()
    print(version) 

i.e. postgresql+psycopg2://test:test@localhost:32779/test does work as the URL.

Some quick Googling suggests there are issues with Windows 10 and Docker named pipes but I can't honestly say they are the ultimate cause of this issue.

Perhaps DockerClient.host() could be changed to return localhost if the host is Windows 10? Happy to submit a patch for that but again I am not 100% that is the "right" thing to do.

petedmarsh avatar Jul 17 '20 22:07 petedmarsh

I am experiencing the same issue on Windows 10. If I subclass PostgresContainer like so then it works:

class X(PostgresContainer):
    def get_connection_url(self):
        return super().get_connection_url().replace('localnpipe', 'localhost')

with X('postgres:12.3') as pg:
    print("HELLO")
    engine = sqlalchemy.create_engine(pg.get_connection_url())
    version, = engine.execute("select version()").fetchone()
    print(version) 

i.e. postgresql+psycopg2://test:test@localhost:32779/test does work as the URL.

Some quick Googling suggests there are issues with Windows 10 and Docker named pipes but I can't honestly say they are the ultimate cause of this issue.

Perhaps DockerClient.host() could be changed to return localhost if the host is Windows 10? Happy to submit a patch for that but again I am not 100% that is the "right" thing to do.

Workaround also confirmed working on arch linux.

greg-el avatar Jul 17 '20 23:07 greg-el

Another way to workaround the issue

# Monkey-patch the get_container_host_ip method
container.get_container_host_ip = lambda: 'localhost'
container.start()

arcann avatar Jan 27 '21 15:01 arcann

I am experiencing the same issue on Windows 10. If I subclass PostgresContainer like so then it works:

class X(PostgresContainer):
    def get_connection_url(self):
        return super().get_connection_url().replace('localnpipe', 'localhost')

with X('postgres:12.3') as pg:
    print("HELLO")
    engine = sqlalchemy.create_engine(pg.get_connection_url())
    version, = engine.execute("select version()").fetchone()
    print(version) 

i.e. postgresql+psycopg2://test:test@localhost:32779/test does work as the URL.

Some quick Googling suggests there are issues with Windows 10 and Docker named pipes but I can't honestly say they are the ultimate cause of this issue.

Perhaps DockerClient.host() could be changed to return localhost if the host is Windows 10? Happy to submit a patch for that but again I am not 100% that is the "right" thing to do.

This workaround works on Windows.

marcrleonard avatar Mar 18 '21 20:03 marcrleonard

Any update on this issue ?

vinchauhan avatar May 05 '21 06:05 vinchauhan

I also got an error running MysqlContainer on Windows because of the same error. If you do not assign TC_HOST value to localhost, it seems to bring docker host information to localnpipe. Why is the Docker client api adpaters information set to http+docker? I think this happened for a different purpose, but I'm curious as to why.

ujkim avatar Aug 08 '21 08:08 ujkim

it seems to bring docker host information to localnpipe. Why is the Docker client api adpaters information set to http+docker? I think this happened for a different purpose, but I'm curious as to why.

it defined in docker-py https://github.com/docker/docker-py/blob/a48a5a9647761406d66e8271f19fab7fa0c5f582/docker/api/client.py#L168 but I don't understad why/

bomzheg avatar Jan 14 '22 16:01 bomzheg

FYI there's some movement in docker-py and a new beta is available already: https://github.com/docker/docker-py/releases/tag/6.0.0b1

It has a lot of fixes related to dependencies and better Windows support

xSAVIKx avatar Jul 30 '22 18:07 xSAVIKx

Same issue with localstack:

raise EndpointConnectionError(endpoint_url=request.url, error=e)
E           botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL: "http://localnpipe:49162/test-bucket"

dwwhitlock avatar Apr 04 '23 18:04 dwwhitlock

You can try this workaround:

os.environ['TC_HOST'] = 'localhost'

YouJiacheng avatar May 09 '23 17:05 YouJiacheng