我有一个看起来像这样的函数:
@app.middleware("http")
async def process_api_event(request: Request, call_next):
url = request.url
path = request.url.path
# request.__setattr__('url', 'sample_url')
# request.url.__ setattr__('path', 'sample_path')
在上面的函数中,我想根据情况改变请求的url,或者路径。我试过了request.__setattr__('url', 'sample_url')
,request.url.__ setattr__('path', 'sample_path')
如上所示,但由于AttributeError: can't set attribute error
. 我通读了 FastAPI 和 Starlette 文档,但在这种情况下找不到我需要的信息。任何帮助将不胜感激!