From 2f84cdd708c16c9950c67e4a2b72a62864a0d2d3 Mon Sep 17 00:00:00 2001 From: messense Date: Mon, 15 May 2017 10:50:13 +0800 Subject: [PATCH] Fix websocket handler bug on Python3.5 with no uvloop --- sanic/app.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sanic/app.py b/sanic/app.py index 8d846c3e..29b8c71c 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -206,7 +206,12 @@ class Sanic: def response(handler): async def websocket_handler(request, *args, **kwargs): request.app = self - protocol = request.transport.get_protocol() + try: + protocol = request.transport.get_protocol() + except AttributeError: + # On Python3.5 the Transport classes in asyncio do not + # have a get_protocol() method as in uvloop + protocol = request.transport._protocol ws = await protocol.websocket_handshake(request) # schedule the application handler