0

i am using init_app() to initialize mongo connection but it won't give me any error at connection despite mongo server is not running, but gives error when fetching the data using find.

mongo = PyMongo()

def create_app(config_name):
    if config_name is None:
        config_name = os.environ.get('FLASK_CONFIG', 'development')

    app = Flask(__name__, instance_relative_config=True)
    app.url_map.strict_slashes = False
    app.config.from_object(app_config[config_name])
    configInstance = app_config[config_name]()
    app.config.from_pyfile(configInstance.FLASK_CONFIG)
    try:
        mongo.init_app(app)
    except PyMongo.errors.ConnectionFailure as e:
        print ("connection gives pymongo.errors.ConnectionFailure --- %s" % (e.message))

gives below error

localhost:27017: [Errno 111] Connection refused
wowkin2
  • 5,895
  • 5
  • 23
  • 66
  • Could you include some more information -- what version of flask and flask-pymongo you're using, what the flask-pymongo-related config is that's being loaded by this code (URI or other settings), etc? – dcrosta Aug 30 '18 at 11:46
  • Can you provide your config file, can't run current code. It has issue: need to change `PyMongo.errors.ConnectionFailure` -> `pymongo.errors.ConnectionFailure` – wowkin2 Aug 31 '18 at 09:54

0 Answers0