我正在使用 init_app() 来初始化 mongo 连接,但尽管 mongo 服务器没有运行,但它不会在连接时给我任何错误,但在使用 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))
给出以下错误
localhost:27017: [Errno 111] Connection refused