嘿伙计们,我正在尝试在生产中运行 Quart。
那是我的代码: setups.py
import quart.flask_patch
from db import *
from http import HTTPStatus
from typing import Optional
import flask.json
from quart import ResponseReturnValue, jsonify, Quart
from quart.ctx import RequestContext
from quart.exceptions import HTTPException
from quart_openapi import Pint
from .confs import __author__, __description__, __mail__, __title__, __version__,SQLALCHEMY_DATABASE_URI
from .routes import initialize_routes
from .user_verify import get_jwks, verify_jwt
class PintCustom(Pint):
def __init__(self, *args, no_openapi: bool = False, **kwargs) -> None:
self.jwks = get_jwks()
super().__init__(*args, no_openapi=no_openapi, **kwargs)
async def preprocess_request(self, request_context: Optional[RequestContext] = None) -> Optional[
ResponseReturnValue]:
token = request_context.request.headers.get('Authorization')
if request_context.request.method != 'OPTIONS':
try:
verify_jwt(str(token), self.jwks)
except Exception:
raise HTTPException(HTTPStatus.UNAUTHORIZED, 403, 'Log in')
return await super().preprocess_request(request_context)
def get_app_instance():
# Initial app.
# app = Quart(__name__)
app = PintCustom(__name__, title=__title__, version=__version__, description=__description__,
contact_email=__mail__, contact=__author__)
@app.errorhandler(HTTPException)
def http_exception(e):
return jsonify(error=e.name, error_details=e.description), e.status_code
app.jwks = get_jwks()
# Initial all the REST API routes.
initialize_routes(app)
# DB
app.config["SQLALCHEMY_DATABASE_URI"] = SQLALCHEMY_DATABASE_URI
db.init_app(app)
return app
服务器.py
__package__ = 'nini'
from .setups import create_app
from .db import db
if __name__ == '__main__':
app = create_app()
db.init_app(app)
app.run(host='127.0.0.1', debug=True)
当我跑步时, hypercorn server:app
我得到:
ModuleNotFoundError:没有名为“nini”的模块
我在 ../nini/server.py 下运行推荐
我没有看到很多关于这方面的教程。还尝试运行:
pipenv install quart
pipenv shell
export QUART_APP=server:app
quart run
同样的错误