Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

flask - Pymongo returns connection refused

I am trying to connect Monogdb to my flask application. But I keep getting this connection error.

This is the error I keep getting:

pymongo.errors.ServerSelectionTimeoutError: csmongodb:27018: [Errno 111] Connection refused

Below are the details:

import pymongo

client = pymongo.MongoClient(app.config['MONGODB_URI'],tls=MONGODB_USE_TLS,tlsAllowInvalidCertificates=True)
database = client.test_db
client.drop_database(test_db)

The MONOGODB_URI format I followed is following:

mongodb://{user}:{pwd}@{host}:{port}/{db}

My docker compose file is something like this:

csmongodb:
    container_name: "cs_mongodb_1"
    image: "mongo:3.6-xenial"
    env_file:
      - ".env"
    volumes:
      - csmongodb:/data/db
    ports:
      - "27018:27018"
    command: mongod --smallfiles --logpath=/dev/null # --quiet
    networks:
      - "backend"

I am using pymongo version 3.9.0

question from:https://stackoverflow.com/questions/66048205/pymongo-returns-connection-refused

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...