Python__模块(代码-辅助)__contextlib / pprint

本文介绍了Python的contextlib模块如何实现自动文件管理和线程操作,以及contextmanager装饰器的使用示例。同时,对pprint模块的PrettyPrinter类及其参数进行了详细说明,展示了美化打印内容的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

contextlib(简介)

上下文管理器。

实现自动的文件打开关闭以及线程操作。


contextlib(参考代码)

contextlib / with 区别

# 例子:with
class echo:
    def __enter__(self):
        print("enter")

    def __exit__(self, *args):
        print("exit")
        print("________________")

with echo() as e:
    print("test")
""" >>>
enter
test
exit
________________
"""

# 例子:contextlib
from contextlib import contextmanager

@contextmanager
def tag(name):
    print("<%s>" % name)
    yield
    print("</%s>" % name)

with tag("ul"):
    print("<li>line1</li>")
    print("<li>line2</li>")
""" >>>
<ul>
<li>line1</li>
<li>line2</li>
</ul>
"""
# 代码的执行顺序:
"""   
with语句首先执行yield之前的语句,因此打印出<h1>
yield调用会执行with语句内部的所有语句,因此打印出hello和world
最后执行yield之后的语句,打印出</h1>
"""

pprint(简介)

美化打印内容。


pprint(参数列表)

【语法】

pprint.PrettyPrinter(width,indent,compact,sort_dicts)

pprint.pprint(对象,流=无,缩进=1,宽度=80,深度=无,*, 紧凑=假,sort_dicts=真,underscore_numbers=假)

【参数】

width

(默认值80) 指定输出中每行所需的最大字符数。

indent

缩进 紧凑会影响长序列(列表、元组、集合等)的格式设置方式。

compact

行格式化

compact  为false(默认值)

则序列的每个项目都将在单独的行上进行格式化

如果紧凑为真,则每个输出行将设置宽度范围内适合的任意数量的项目。

sort_dicts

键排序

sort_dicts为True(默认值),则字典的格式将按键排序。

否则将按广告插入顺序显示。


pprint(参考代码)

简单例子

import pprint

# 简化版
obj = {"word": {"test": "测试"}, "fruit": {"apple": "苹果"}}
pprint.pprint(obj)
# 样式版
words = {
    "apple": "苹果",
    "banana": "香蕉",
    "watermelon": "西瓜",
    "grape": "葡萄",
    "orange": "橙子",
}
pprint.pprint(words)
p = pprint.PrettyPrinter(width=1, indent=1, compact=True, sort_dicts=False)
p.pprint(words)

2025-07-23 16:48:26 2025-07-23 16:48:26.051 | INFO | uvicorn.protocols.http.httptools_impl:send:476 - 172.18.0.1:0 - "POST /api/v1/images/image/config/update HTTP/1.1" 500 - {} 2025-07-23 16:48:26 Exception in ASGI application 2025-07-23 16:48:26 + Exception Group Traceback (most recent call last): 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/_utils.py", line 76, in collapse_excgroups 2025-07-23 16:48:26 | yield 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 178, in __call__ 2025-07-23 16:48:26 | async with anyio.create_task_group() as task_group: 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 772, in __aexit__ 2025-07-23 16:48:26 | raise BaseExceptionGroup( 2025-07-23 16:48:26 | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception) 2025-07-23 16:48:26 +-+---------------- 1 ---------------- 2025-07-23 16:48:26 | Traceback (most recent call last): 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 409, in run_asgi 2025-07-23 16:48:26 | result = await app( # type: ignore[func-returns-value] 2025-07-23 16:48:26 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__ 2025-07-23 16:48:26 | return await self.app(scope, receive, send) 2025-07-23 16:48:26 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__ 2025-07-23 16:48:26 | await super().__call__(scope, receive, send) 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/applications.py", line 112, in __call__ 2025-07-23 16:48:26 | await self.middleware_stack(scope, receive, send) 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 187, in __call__ 2025-07-23 16:48:26 | raise exc 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 165, in __call__ 2025-07-23 16:48:26 | await self.app(scope, receive, _send) 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/cors.py", line 85, in __call__ 2025-07-23 16:48:26 | await self.app(scope, receive, send) 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 177, in __call__ 2025-07-23 16:48:26 | with recv_stream, send_stream, collapse_excgroups(): 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/contextlib.py", line 158, in __exit__ 2025-07-23 16:48:26 | self.gen.throw(typ, value, traceback) 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/_utils.py", line 82, in collapse_excgroups 2025-07-23 16:48:26 | raise exc 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 179, in __call__ 2025-07-23 16:48:26 | response = await self.dispatch_func(request, call_next) 2025-07-23 16:48:26 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 | File "/app/backend/open_webui/main.py", line 1117, in inspect_websocket 2025-07-23 16:48:26 | return await call_next(request) 2025-07-23 16:48:26 | ^^^^^^^^^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 154, in call_next 2025-07-23 16:48:26 | raise app_exc 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 141, in coro 2025-07-23 16:48:26 | await self.app(scope, receive_or_disconnect, send_no_error) 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 177, in __call__ 2025-07-23 16:48:26 | with recv_stream, send_stream, collapse_excgroups(): 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/contextlib.py", line 158, in __exit__ 2025-07-23 16:48:26 | self.gen.throw(typ, value, traceback) 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/_utils.py", line 82, in collapse_excgroups 2025-07-23 16:48:26 | raise exc 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 179, in __call__ 2025-07-23 16:48:26 | response = await self.dispatch_func(request, call_next) 2025-07-23 16:48:26 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 | File "/app/backend/open_webui/main.py", line 1096, in check_url 2025-07-23 16:48:26 | response = await call_next(request) 2025-07-23 16:48:26 | ^^^^^^^^^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 154, in call_next 2025-07-23 16:48:26 | raise app_exc 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 141, in coro 2025-07-23 16:48:26 | await self.app(scope, receive_or_disconnect, send_no_error) 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 177, in __call__ 2025-07-23 16:48:26 | with recv_stream, send_stream, collapse_excgroups(): 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/contextlib.py", line 158, in __exit__ 2025-07-23 16:48:26 | self.gen.throw(typ, value, traceback) 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/_utils.py", line 82, in collapse_excgroups 2025-07-23 16:48:26 | raise exc 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 179, in __call__ 2025-07-23 16:48:26 | response = await self.dispatch_func(request, call_next) 2025-07-23 16:48:26 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 | File "/app/backend/open_webui/main.py", line 1082, in commit_session_after_request 2025-07-23 16:48:26 | response = await call_next(request) 2025-07-23 16:48:26 | ^^^^^^^^^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 154, in call_next 2025-07-23 16:48:26 | raise app_exc 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 141, in coro 2025-07-23 16:48:26 | await self.app(scope, receive_or_disconnect, send_no_error) 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 177, in __call__ 2025-07-23 16:48:26 | with recv_stream, send_stream, collapse_excgroups(): 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/contextlib.py", line 158, in __exit__ 2025-07-23 16:48:26 | self.gen.throw(typ, value, traceback) 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/_utils.py", line 82, in collapse_excgroups 2025-07-23 16:48:26 | raise exc 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 179, in __call__ 2025-07-23 16:48:26 | response = await self.dispatch_func(request, call_next) 2025-07-23 16:48:26 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 | File "/app/backend/open_webui/utils/security_headers.py", line 11, in dispatch 2025-07-23 16:48:26 | response = await call_next(request) 2025-07-23 16:48:26 | ^^^^^^^^^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 154, in call_next 2025-07-23 16:48:26 | raise app_exc 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 141, in coro 2025-07-23 16:48:26 | await self.app(scope, receive_or_disconnect, send_no_error) 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 177, in __call__ 2025-07-23 16:48:26 | with recv_stream, send_stream, collapse_excgroups(): 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/contextlib.py", line 158, in __exit__ 2025-07-23 16:48:26 | self.gen.throw(typ, value, traceback) 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/_utils.py", line 82, in collapse_excgroups 2025-07-23 16:48:26 | raise exc 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 179, in __call__ 2025-07-23 16:48:26 | response = await self.dispatch_func(request, call_next) 2025-07-23 16:48:26 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 | File "/app/backend/open_webui/main.py", line 1070, in dispatch 2025-07-23 16:48:26 | response = await call_next(request) 2025-07-23 16:48:26 | ^^^^^^^^^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 154, in call_next 2025-07-23 16:48:26 | raise app_exc 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 141, in coro 2025-07-23 16:48:26 | await self.app(scope, receive_or_disconnect, send_no_error) 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette_compress/__init__.py", line 94, in __call__ 2025-07-23 16:48:26 | return await self._brotli(scope, receive, send) 2025-07-23 16:48:26 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette_compress/_brotli.py", line 106, in __call__ 2025-07-23 16:48:26 | await self.app(scope, receive, wrapper) 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 62, in __call__ 2025-07-23 16:48:26 | await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app 2025-07-23 16:48:26 | raise exc 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app 2025-07-23 16:48:26 | await app(scope, receive, sender) 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 715, in __call__ 2025-07-23 16:48:26 | await self.middleware_stack(scope, receive, send) 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 735, in app 2025-07-23 16:48:26 | await route.handle(scope, receive, send) 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 288, in handle 2025-07-23 16:48:26 | await self.app(scope, receive, send) 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 76, in app 2025-07-23 16:48:26 | await wrap_app_handling_exceptions(app, request)(scope, receive, send) 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app 2025-07-23 16:48:26 | raise exc 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app 2025-07-23 16:48:26 | await app(scope, receive, sender) 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 73, in app 2025-07-23 16:48:26 | response = await f(request) 2025-07-23 16:48:26 | ^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/fastapi/routing.py", line 301, in app 2025-07-23 16:48:26 | raw_response = await run_endpoint_function( 2025-07-23 16:48:26 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 | File "/usr/local/lib/python3.11/site-packages/fastapi/routing.py", line 212, in run_endpoint_function 2025-07-23 16:48:26 | return await dependant.call(**values) 2025-07-23 16:48:26 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 | File "/app/backend/open_webui/routers/images.py", line 303, in update_image_config 2025-07-23 16:48:26 | set_image_model(request, form_data.MODEL) 2025-07-23 16:48:26 | File "/app/backend/open_webui/routers/images.py", line 239, in set_image_model 2025-07-23 16:48:26 | if model != options["sd_model_checkpoint"]: 2025-07-23 16:48:26 | ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 | KeyError: 'sd_model_checkpoint' 2025-07-23 16:48:26 +------------------------------------ 2025-07-23 16:48:26 2025-07-23 16:48:26 During handling of the above exception, another exception occurred: 2025-07-23 16:48:26 2025-07-23 16:48:26 Traceback (most recent call last): 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 409, in run_asgi 2025-07-23 16:48:26 result = await app( # type: ignore[func-returns-value] 2025-07-23 16:48:26 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__ 2025-07-23 16:48:26 return await self.app(scope, receive, send) 2025-07-23 16:48:26 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__ 2025-07-23 16:48:26 await super().__call__(scope, receive, send) 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/applications.py", line 112, in __call__ 2025-07-23 16:48:26 await self.middleware_stack(scope, receive, send) 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 187, in __call__ 2025-07-23 16:48:26 raise exc 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 165, in __call__ 2025-07-23 16:48:26 await self.app(scope, receive, _send) 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/middleware/cors.py", line 85, in __call__ 2025-07-23 16:48:26 await self.app(scope, receive, send) 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 177, in __call__ 2025-07-23 16:48:26 with recv_stream, send_stream, collapse_excgroups(): 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/contextlib.py", line 158, in __exit__ 2025-07-23 16:48:26 self.gen.throw(typ, value, traceback) 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/_utils.py", line 82, in collapse_excgroups 2025-07-23 16:48:26 raise exc 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 179, in __call__ 2025-07-23 16:48:26 response = await self.dispatch_func(request, call_next) 2025-07-23 16:48:26 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 File "/app/backend/open_webui/main.py", line 1117, in inspect_websocket 2025-07-23 16:48:26 return await call_next(request) 2025-07-23 16:48:26 ^^^^^^^^^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 154, in call_next 2025-07-23 16:48:26 raise app_exc 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 141, in coro 2025-07-23 16:48:26 await self.app(scope, receive_or_disconnect, send_no_error) 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 177, in __call__ 2025-07-23 16:48:26 with recv_stream, send_stream, collapse_excgroups(): 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/contextlib.py", line 158, in __exit__ 2025-07-23 16:48:26 self.gen.throw(typ, value, traceback) 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/_utils.py", line 82, in collapse_excgroups 2025-07-23 16:48:26 raise exc 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 179, in __call__ 2025-07-23 16:48:26 response = await self.dispatch_func(request, call_next) 2025-07-23 16:48:26 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 File "/app/backend/open_webui/main.py", line 1096, in check_url 2025-07-23 16:48:26 response = await call_next(request) 2025-07-23 16:48:26 ^^^^^^^^^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 154, in call_next 2025-07-23 16:48:26 raise app_exc 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 141, in coro 2025-07-23 16:48:26 await self.app(scope, receive_or_disconnect, send_no_error) 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 177, in __call__ 2025-07-23 16:48:26 with recv_stream, send_stream, collapse_excgroups(): 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/contextlib.py", line 158, in __exit__ 2025-07-23 16:48:26 self.gen.throw(typ, value, traceback) 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/_utils.py", line 82, in collapse_excgroups 2025-07-23 16:48:26 raise exc 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 179, in __call__ 2025-07-23 16:48:26 response = await self.dispatch_func(request, call_next) 2025-07-23 16:48:26 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 File "/app/backend/open_webui/main.py", line 1082, in commit_session_after_request 2025-07-23 16:48:26 response = await call_next(request) 2025-07-23 16:48:26 ^^^^^^^^^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 154, in call_next 2025-07-23 16:48:26 raise app_exc 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 141, in coro 2025-07-23 16:48:26 await self.app(scope, receive_or_disconnect, send_no_error) 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 177, in __call__ 2025-07-23 16:48:26 with recv_stream, send_stream, collapse_excgroups(): 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/contextlib.py", line 158, in __exit__ 2025-07-23 16:48:26 self.gen.throw(typ, value, traceback) 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/_utils.py", line 82, in collapse_excgroups 2025-07-23 16:48:26 raise exc 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 179, in __call__ 2025-07-23 16:48:26 response = await self.dispatch_func(request, call_next) 2025-07-23 16:48:26 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 File "/app/backend/open_webui/utils/security_headers.py", line 11, in dispatch 2025-07-23 16:48:26 response = await call_next(request) 2025-07-23 16:48:26 ^^^^^^^^^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 154, in call_next 2025-07-23 16:48:26 raise app_exc 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 141, in coro 2025-07-23 16:48:26 await self.app(scope, receive_or_disconnect, send_no_error) 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 177, in __call__ 2025-07-23 16:48:26 with recv_stream, send_stream, collapse_excgroups(): 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/contextlib.py", line 158, in __exit__ 2025-07-23 16:48:26 self.gen.throw(typ, value, traceback) 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/_utils.py", line 82, in collapse_excgroups 2025-07-23 16:48:26 raise exc 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 179, in __call__ 2025-07-23 16:48:26 response = await self.dispatch_func(request, call_next) 2025-07-23 16:48:26 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 File "/app/backend/open_webui/main.py", line 1070, in dispatch 2025-07-23 16:48:26 response = await call_next(request) 2025-07-23 16:48:26 ^^^^^^^^^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 154, in call_next 2025-07-23 16:48:26 raise app_exc 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 141, in coro 2025-07-23 16:48:26 await self.app(scope, receive_or_disconnect, send_no_error) 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette_compress/__init__.py", line 94, in __call__ 2025-07-23 16:48:26 return await self._brotli(scope, receive, send) 2025-07-23 16:48:26 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette_compress/_brotli.py", line 106, in __call__ 2025-07-23 16:48:26 await self.app(scope, receive, wrapper) 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 62, in __call__ 2025-07-23 16:48:26 await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app 2025-07-23 16:48:26 raise exc 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app 2025-07-23 16:48:26 await app(scope, receive, sender) 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 715, in __call__ 2025-07-23 16:48:26 await self.middleware_stack(scope, receive, send) 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 735, in app 2025-07-23 16:48:26 await route.handle(scope, receive, send) 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 288, in handle 2025-07-23 16:48:26 await self.app(scope, receive, send) 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 76, in app 2025-07-23 16:48:26 await wrap_app_handling_exceptions(app, request)(scope, receive, send) 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app 2025-07-23 16:48:26 raise exc 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app 2025-07-23 16:48:26 await app(scope, receive, sender) 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 73, in app 2025-07-23 16:48:26 response = await f(request) 2025-07-23 16:48:26 ^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/fastapi/routing.py", line 301, in app 2025-07-23 16:48:26 raw_response = await run_endpoint_function( 2025-07-23 16:48:26 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 File "/usr/local/lib/python3.11/site-packages/fastapi/routing.py", line 212, in run_endpoint_function 2025-07-23 16:48:26 return await dependant.call(**values) 2025-07-23 16:48:26 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 File "/app/backend/open_webui/routers/images.py", line 303, in update_image_config 2025-07-23 16:48:26 set_image_model(request, form_data.MODEL) 2025-07-23 16:48:26 File "/app/backend/open_webui/routers/images.py", line 239, in set_image_model 2025-07-23 16:48:26 if model != options["sd_model_checkpoint"]: 2025-07-23 16:48:26 ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^ 2025-07-23 16:48:26 KeyError: 'sd_model_checkpoint'
最新发布
07-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

vip飞梦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值