diff --git a/websocket/_handshake.py b/websocket/_handshake.py index eee1544..4d0f028 100644 --- a/websocket/_handshake.py +++ b/websocket/_handshake.py @@ -30,6 +30,7 @@ import uuid import hashlib import hmac import os +import sys from ._logging import * from ._url import * @@ -148,7 +149,11 @@ def _validate(headers, key, subprotocols): value = (key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11").encode('utf-8') hashed = base64encode(hashlib.sha1(value).digest()).strip().lower() - success = hmac.compare_digest(hashed, result) + if sys.version_info[0] == 2 and sys.version_info[1] < 7: + success = (hashed == result) + else: + success = hmac.compare_digest(hashed, result) + if success: return True, subproto else: