Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dbaskarraj opened this issue Jul 5, 2020 · 12 comments
Open

Comments

@dbaskarraj
Copy link

dbaskarraj commented Jul 5, 2020

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.

@tillahoffmann
Copy link
Collaborator

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

@petedmarsh
Copy link

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.

@greg-el
Copy link

greg-el commented Jul 17, 2020

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.

@arcann
Copy link

arcann commented Jan 27, 2021

Another way to workaround the issue

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

@marcrleonard
Copy link

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.

@vinchauhan
Copy link

Any update on this issue ?

@ujkim
Copy link

ujkim commented Aug 8, 2021

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.

@bomzheg
Copy link

bomzheg commented Jan 14, 2022

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/

@xSAVIKx
Copy link

xSAVIKx commented Jul 30, 2022

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

@dwwhitlock
Copy link

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"

@YouJiacheng
Copy link

You can try this workaround:

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

@alexanderankin
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests