简体   繁体   English

从容器连接到 Atlas mongoDB 的超时错误

[英]Timeout error connecting to Atlas mongoDB from a container

My application can connect to my Atlas mongodb when I run it on local without a container.当我在没有容器的本地运行它时,我的应用程序可以连接到我的 Atlas mongodb。

When I put my application in a container I am unable to access the Atlas mongodb.当我将应用程序放入容器时,我无法访问 Atlas mongodb。

I have whitelisted all IP's.我已将所有 IP 列入白名单。

        self.myclient = pymongo.MongoClient(mongodb+srv://admin:<password>@mongodbscrapperconf-lctzq.gcp.mongodb.net/test?retryWrites=true&w=majority&ssl=true&authSource=admin)

I have tried both to connect to my Atlas database on local with my container and running my container in GCP.我已经尝试使用我的容器连接到本地的 Atlas 数据库并在 GCP 中运行我的容器。 In both cases I am getting a timeout error from mongoDB.在这两种情况下,我都收到来自 mongoDB 的超时错误。

My DockerFile is looking like我的 DockerFile 看起来像

FROM python:3.7
COPY . /app
WORKDIR /app
RUN apt-get update && apt-get install ca-certificates && rm -rf /var/cache/apk/*
COPY ./host.crt /usr/local/share/ca-certificates
RUN update-ca-certificates
RUN pip install -r requirements.txt
EXPOSE 8000
CMD python ./controller.py cloud

requirements.txt要求.txt

iso4217
validators
pymongo
pymongo[srv]
flask
lxml
flask-cors
configparser

UPDATED: I found out that the connection is encrypted and the connection need to accept SSL certificates.更新:我发现连接是加密的,连接需要接受 SSL 证书。 I have tried this but Atlas is still refusing the connection.我已经尝试过了,但 Atlas 仍然拒绝连接。

I think you need also to add pyopenssl to your requirments.txt我认为您还需要将pyopenssl添加到您的requirments.txt

I solve the issue by adding我通过添加解决了这个问题

pymongo[tls,srv]

To the requirements.txt到 requirements.txt

This is the resulting requirements.txt这是生成的 requirements.txt

iso4217
validators
pymongo[tls,srv]
flask
lxml
flask-cors
configparser

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 Google Colaboratory 连接到 Mongodb Atlas 时出错 - Error connecting to Mongodb Atlas from Google Colaboratory 通过地图集连接到 mongodb 的 Pymongo 错误 - Pymongo error connecting to mongodb via atlas 连接到 mongodb Atlas 时出现此错误:“dns.exception.Timeout:DNS 操作在 30.000985383987427 秒后超时” - i am getting this error while connecting to mongodb Atlas: "dns.exception.Timeout: The DNS operation timed out after 30.000985383987427 seconds" 连接本地MongoDB和MongoDB图集 - Connecting to a local MongoDB and MongoDB Atlas PyMongo 无法从 Azure 容器实例连接到 MongoDB Atlas - PyMongo Cant connect to MongoDB Atlas from Azure Container Instance 使用 python 连接到 mongodb 地图集时出现问题 - Problem connecting to mongodb atlas using python 使用 pymongo 连接到 Atlas MongoDb - ServerSelectionTimeoutError - Connecting to Atlas MongoDb using pymongo - ServerSelectionTimeoutError "ObjectId' object is not iterable" 错误,同时从 MongoDB Atlas 中获取数据 - "ObjectId' object is not iterable" error, while fetching data from MongoDB Atlas 从Docker连接到MongoDB Cloud时出错 - Error connecting to MongoDB Cloud from Docker 将AWS Lamba上的Python / Zappa项目连接到Mongodb Atlas - Connecting a Python/Zappa Project on AWS Lamba to Mongodb Atlas
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM