Posts

Showing posts with the label Flask

Authentication Failed When Using Flask_pymongo

Answer : This question may be old, but I was experiencing the same issue and found another solution that might work for others. Appending ?authSource=admin to the end of your MONGO_URI variable will authenticate your credentials against the admin database, rather than the one you're connecting to. Example: app.config["MONGO_URI"] = "mongodb://username:password@host:port/db_name?authSource=admin" The problem is if you use the MONGO_URI config parameter then pymongo attempts to authenticate against the db name included in the string. You should break up the config parameters into the following so you can specify a db name and an auth source. app.config['MONGO_HOST'] = 'localhost' app.config['MONGO_PORT'] = '27017' app.config['MONGO_DBNAME'] = 'mongo_test' app.config['MONGO_USERNAME'] = 'root' app.config['MONGO_PASSWORD'] = 'aaa2016' app.config['MONGO_AUTH_SOURCE']...

Architecture Flask Vs FastAPI

Answer : This seemed a little interesting, so i ran a little tests with ApacheBench : Flask from flask import Flask from flask_restful import Resource, Api app = Flask(__name__) api = Api(app) class Root(Resource): def get(self): return {"message": "hello"} api.add_resource(Root, "/") FastAPI from fastapi import FastAPI app = FastAPI(debug=False) @app.get("/") async def root(): return {"message": "hello"} I ran 2 tests for FastAPI, there was a huge difference: gunicorn -w 4 -k uvicorn.workers.UvicornWorker fast_api:app uvicorn fast_api:app --reload So here is the benchmarking results for 5000 requests with a concurrency of 500: FastAPI with Uvicorn Workers Concurrency Level: 500 Time taken for tests: 0.577 seconds Complete requests: 5000 Failed requests: 0 Total transferred: 720000 bytes HTML transferred: 95000 bytes Requests per second: 8665.48 [#/sec] ...