Browse Source
Support Python's ConnectionRefusedError to reject a connection
pull/1515/head
Miguel Grinberg
8 months ago
Failed to extract signature
3 changed files with
8 additions and
0 deletions
-
docs/server.rst
-
src/socketio/async_server.py
-
src/socketio/server.py
|
|
|
@ -246,6 +246,8 @@ a :class:`socketio.exceptions.ConnectionRefusedError` exception can be raised, |
|
|
|
and all of its arguments will be sent to the client with the rejection |
|
|
|
message:: |
|
|
|
|
|
|
|
from socketio.exceptions import ConnectionRefusedError |
|
|
|
|
|
|
|
@sio.event |
|
|
|
def connect(sid, environ, auth): |
|
|
|
raise ConnectionRefusedError('authentication failed') |
|
|
|
|
|
|
|
@ -561,6 +561,9 @@ class AsyncServer(base_server.BaseServer): |
|
|
|
except exceptions.ConnectionRefusedError as exc: |
|
|
|
fail_reason = exc.error_args |
|
|
|
success = False |
|
|
|
except ConnectionRefusedError as exc: |
|
|
|
fail_reason = {"message": "Connection refused by server"} |
|
|
|
success = False |
|
|
|
|
|
|
|
if success is False: |
|
|
|
if self.always_connect: |
|
|
|
|
|
|
|
@ -543,6 +543,9 @@ class Server(base_server.BaseServer): |
|
|
|
except exceptions.ConnectionRefusedError as exc: |
|
|
|
fail_reason = exc.error_args |
|
|
|
success = False |
|
|
|
except ConnectionRefusedError as exc: |
|
|
|
fail_reason = {"message": "Connection refused by server"} |
|
|
|
success = False |
|
|
|
|
|
|
|
if success is False: |
|
|
|
if self.always_connect: |
|
|
|
|