Подключение flask и удаленный пн go дБ - PullRequest
0 голосов
/ 22 апреля 2020

Я пытаюсь начать работать с flask и mongoDB.
Я создал кластер и коллекцию (Изображение добавлено).
Я установил mongoDB локально, используя brew, и запустил его, используя brew services start mongodb-community.
Я добавляю код python и получаю сообщение об ошибке при попытке отправить запрос на локальный хост: 5000.

Пожалуйста, дайте мне знать, что я делаю неправильно.
Заранее спасибо!

enter image description here

from flask import Flask
from flask import jsonify
from flask_pymongo import PyMongo

app = Flask(__name__)

app.config['MONGO_DBNAME'] = 'python_connection'
app.config[
    'MONGO_URI'] = 'mongodb+srv://myUserName:<myPassword>@cluster0-eipr0.mongodb.net/test?retryWrites=true&w=majority'
mongo = PyMongo(app)


@app.route("/")
def index():
    col = mongo.db['first_collection']
    a = col.find()[0]
    return jsonify({'result': a.name})


if __name__ == "__main__":
    app.run(debug=True)

 * Serving Flask app "run" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 757-787-258
127.0.0.1 - - [22/Apr/2020 15:30:52] "GET / HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/Users/avishaiyaniv/development/mobile/flutter_flask/backend/server/env/lib/python3.8/site-packages/flask/app.py", line 2464, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/avishaiyaniv/development/mobile/flutter_flask/backend/server/env/lib/python3.8/site-packages/flask/app.py", line 2450, in wsgi_app
    response = self.handle_exception(e)
  File "/Users/avishaiyaniv/development/mobile/flutter_flask/backend/server/env/lib/python3.8/site-packages/flask/app.py", line 1867, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/avishaiyaniv/development/mobile/flutter_flask/backend/server/env/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/Users/avishaiyaniv/development/mobile/flutter_flask/backend/server/env/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/avishaiyaniv/development/mobile/flutter_flask/backend/server/env/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/avishaiyaniv/development/mobile/flutter_flask/backend/server/env/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/avishaiyaniv/development/mobile/flutter_flask/backend/server/env/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/Users/avishaiyaniv/development/mobile/flutter_flask/backend/server/env/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/avishaiyaniv/development/mobile/flutter_flask/backend/server/env/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/avishaiyaniv/development/mobile/flutter_flask/backend/server/run.py", line 16, in index
    a = col.find()[0]
  File "/Users/avishaiyaniv/development/mobile/flutter_flask/backend/server/env/lib/python3.8/site-packages/pymongo/cursor.py", line 614, in __getitem__
    for doc in clone:
  File "/Users/avishaiyaniv/development/mobile/flutter_flask/backend/server/env/lib/python3.8/site-packages/pymongo/cursor.py", line 1156, in next
    if len(self.__data) or self._refresh():
  File "/Users/avishaiyaniv/development/mobile/flutter_flask/backend/server/env/lib/python3.8/site-packages/pymongo/cursor.py", line 1050, in _refresh
    self.__session = self.__collection.database.client._ensure_session()
  File "/Users/avishaiyaniv/development/mobile/flutter_flask/backend/server/env/lib/python3.8/site-packages/pymongo/mongo_client.py", line 1810, in _ensure_session
    return self.__start_session(True, causal_consistency=False)
  File "/Users/avishaiyaniv/development/mobile/flutter_flask/backend/server/env/lib/python3.8/site-packages/pymongo/mongo_client.py", line 1763, in __start_session
    server_session = self._get_server_session()
  File "/Users/avishaiyaniv/development/mobile/flutter_flask/backend/server/env/lib/python3.8/site-packages/pymongo/mongo_client.py", line 1796, in _get_server_session
    return self._topology.get_server_session()
  File "/Users/avishaiyaniv/development/mobile/flutter_flask/backend/server/env/lib/python3.8/site-packages/pymongo/topology.py", line 487, in get_server_session
    self._select_servers_loop(
  File "/Users/avishaiyaniv/development/mobile/flutter_flask/backend/server/env/lib/python3.8/site-packages/pymongo/topology.py", line 208, in _select_servers_loop
    raise ServerSelectionTimeoutError(
pymongo.errors.ServerSelectionTimeoutError: cluster0-shard-00-02-eipr0.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108),cluster0-shard-00-01-eipr0.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108),cluster0-shard-00-00-eipr0.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)


Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...