testcontainers / testcontainers/testcontainers-python

MongoDbContainer on Windows 10 fails with getaddrinfo error

未关闭
#99 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

👀 requires attention 📦 package: mongodb 🪟 windows
主要语言
Python
星标
2.3k
派生
386
平均合并
4 小时 40 分钟
30 天内合并 PR
1

描述

The following code fails with testcontainers-python 3.0.2:

from testcontainers.mongodb import MongoDbContainer
with MongoDbContainer('mongo:4.2.2') as mongo_:
...     db = mongo_.get_connection_client().test
...     db.test.insert_one({'foo': 'bar'})

with

Pulling image mongo:4.2.2
Container started:  d5ca66c443
Traceback (most recent call last):
  File "<input>", line 3, in <module>
  File "C:\...\venv\lib\site-packages\pymongo\collection.py", line 695, in insert_one
    self._insert(document,
  File "C:\...\venv\lib\site-packages\pymongo\collection.py", line 610, in _insert
    return self._insert_one(
  File "C:\...\venv\lib\site-packages\pymongo\collection.py", line 599, in _insert_one
    self.__database.client._retryable_write(
  File "C:\...\venv\lib\site-packages\pymongo\mongo_client.py", line 1490, in _retryable_write
    with self._tmp_session(session) as s:
  File "C:\Program Files\Python38\lib\contextlib.py", line 113, in __enter__
    return next(self.gen)
  File "C:\...\venv\lib\site-packages\pymongo\mongo_client.py", line 1823, in _tmp_session
    s = self._ensure_session(session)
  File "C:\...\venv\lib\site-packages\pymongo\mongo_client.py", line 1810, in _ensure_session
    return self.__start_session(True, causal_consistency=False)
  File "C:\...\venv\lib\site-packages\pymongo\mongo_client.py", line 1763, in __start_session
    server_session = self._get_server_session()
  File "C:\...\venv\lib\site-packages\pymongo\mongo_client.py", line 1796, in _get_server_session
    return self._topology.get_server_session()
  File "C:\...\venv\lib\site-packages\pymongo\topology.py", line 482, in get_server_session
    self._select_servers_loop(
  File "C:\...\venv\lib\site-packages\pymongo\topology.py", line 208, in _select_servers_loop
    raise ServerSelectionTimeoutError(
pymongo.errors.ServerSelectionTimeoutError: localnpipe:32775: [Errno 11001] getaddrinfo failed

Interestingly, the MongoDbContainer.get_connection_url() method returns a URL with hostname localnpipe, which I suspect the mongo client does not understand. Using pymongo directly, I can connect to the created container using a hostname of localhost.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 MongoDbContainer.get_connection_url() 开始,在 Windows 10 上复现所示的 MongoDbContainer 示例,并将其与使用 localhost 的直接 PyMongo 连接进行比较。完成的标准是,返回的连接 URL 使用 PyMongo 接受的主机名,并且 insert 成功且没有 getaddrinfo 错误。

由索引模型根据 Issue 内容生成。

评估

技术栈
docker, mongodb, python
领域
databases, testing
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。