浏览代码

Merge pull request #5773 from HaldiH/main

fix: Chat completion 401 when no Authorization header
Timothy Jaeryang Baek 7 月之前
父节点
当前提交
6e9db3e3c8
共有 1 个文件被更改,包括 16 次插入4 次删除
  1. 16 4
      backend/open_webui/main.py

+ 16 - 4
backend/open_webui/main.py

@@ -761,10 +761,22 @@ class PipelineMiddleware(BaseHTTPMiddleware):
         # Parse string to JSON
         data = json.loads(body_str) if body_str else {}
 
-        user = get_current_user(
-            request,
-            get_http_authorization_cred(request.headers["Authorization"]),
-        )
+        try:
+            user = get_current_user(
+                request,
+                get_http_authorization_cred(request.headers["Authorization"]),
+            )
+        except KeyError as e:
+            if len(e.args) > 1:
+                return JSONResponse(
+                    status_code=e.args[0],
+                    content={"detail": e.args[1]},
+                )
+            else:
+                return JSONResponse(
+                    status_code=status.HTTP_401_UNAUTHORIZED,
+                    content={"detail": "Not authenticated"},
+                )
 
         try:
             data = filter_pipeline(data, user)