🔀 Merge pull request #452

修复由于 quart.exception在新版Quart被移除导致import出错
This commit is contained in:
Ju4tCode 2021-07-26 11:16:00 +08:00 committed by GitHub
commit 600fc4fffd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,7 +21,7 @@ from nonebot.config import Env, Config as NoneBotConfig
from nonebot.drivers import ReverseDriver, HTTPRequest, WebSocket as BaseWebSocket from nonebot.drivers import ReverseDriver, HTTPRequest, WebSocket as BaseWebSocket
try: try:
from quart import exceptions from werkzeug import exceptions
from quart import request as _request from quart import request as _request
from quart import websocket as _websocket from quart import websocket as _websocket
from quart import Quart, Request, Response from quart import Quart, Request, Response
@ -167,10 +167,8 @@ class Driver(ReverseDriver):
self_id, response = await BotClass.check_permission(self, http_request) self_id, response = await BotClass.check_permission(self, http_request)
if not self_id: if not self_id:
raise exceptions.HTTPException( raise exceptions.Unauthorized(
response and response.status or 401, description=(response and response.body or b"").decode())
description=(response and response.body or b"").decode(),
name="Request Denied")
if self_id in self._clients: if self_id in self._clients:
logger.warning("There's already a reverse websocket connection," logger.warning("There's already a reverse websocket connection,"
"so the event may be handled twice.") "so the event may be handled twice.")
@ -195,18 +193,14 @@ class Driver(ReverseDriver):
self_id, response = await BotClass.check_permission(self, ws) self_id, response = await BotClass.check_permission(self, ws)
if not self_id: if not self_id:
raise exceptions.HTTPException( raise exceptions.Unauthorized(
response and response.status or 401, description=(response and response.body or b"").decode())
description=(response and response.body or b"").decode(),
name="Request Denied")
if self_id in self._clients: if self_id in self._clients:
logger.opt(colors=True).warning( logger.opt(colors=True).warning(
"There's already a reverse websocket connection, " "There's already a reverse websocket connection, "
f"<y>{adapter.upper()} Bot {self_id}</y> ignored.") f"<y>{adapter.upper()} Bot {self_id}</y> ignored.")
raise exceptions.HTTPException(403, raise exceptions.Forbidden(description='Client already exists.')
description="Client already exists",
name="Request Denied")
bot = BotClass(self_id, ws) bot = BotClass(self_id, ws)
await ws.accept() await ws.accept()