Fixed websocket and encoding errors

This commit is contained in:
FinnStutzenstein 2019-05-10 07:35:19 +02:00
parent c868a04571
commit 5728b65824
2 changed files with 11 additions and 4 deletions

View File

@ -647,7 +647,9 @@ class PasswordResetView(APIView):
"protocol": "https" if self.use_https else "http", "protocol": "https" if self.use_https else "http",
"domain": current_site.domain, "domain": current_site.domain,
"path": "/login/reset-password-confirm/", "path": "/login/reset-password-confirm/",
"user_id": urlsafe_base64_encode(force_bytes(user.pk)).decode(), "user_id": urlsafe_base64_encode(
force_bytes(user.pk)
), # urlsafe_base64_encode decodes to ascii
"token": default_token_generator.make_token(user), "token": default_token_generator.make_token(user),
"username": user.get_username(), "username": user.get_username(),
} }

View File

@ -25,8 +25,8 @@ class ProtocollAsyncJsonWebsocketConsumer(AsyncJsonWebsocketConsumer):
) -> None: ) -> None:
""" """
Sends the data with the type. Sends the data with the type.
If silence_errors is True (default), all ConnectionClosed errors If silence_errors is True (default), all ConnectionClosed
during sending will be ignored. and runtime errors during sending will be ignored.
""" """
out = {"type": type, "content": content} out = {"type": type, "content": content}
if id: if id:
@ -35,7 +35,12 @@ class ProtocollAsyncJsonWebsocketConsumer(AsyncJsonWebsocketConsumer):
out["in_response"] = in_response out["in_response"] = in_response
try: try:
await super().send_json(out) await super().send_json(out)
except ConnectionClosed as e: except (ConnectionClosed, RuntimeError) as e:
# The ConnectionClosed error is thrown by the websocket lib: websocket/protocol.py in ensure_open
# `websockets.exceptions.ConnectionClosed: WebSocket connection is closed: code = 1005
# (no status code [internal]), no reason` (Also with other codes)
# The RuntimeError is thrown by uvicorn: uvicorn/protocols/websockets/websockets_impl.py in asgi_send
# `RuntimeError: Unexpected ASGI message 'websocket.send', after sending 'websocket.close'`
if not silence_errors: if not silence_errors:
raise e raise e