diff options
author | engn33r <engn33r@users.noreply.github.com> | 2023-04-07 00:00:00 +0000 |
---|---|---|
committer | engn33r <engn33r@users.noreply.github.com> | 2023-04-07 00:00:00 +0000 |
commit | f85ae1fa2ad950469826187e3965f40d90ebb844 (patch) | |
tree | 8d34890e90fde533bd9e14b246137f725dd473e2 | |
parent | 1ececb4714058439bc57aad1e7ee9b78d23ea261 (diff) | |
download | websocket-client-f85ae1fa2ad950469826187e3965f40d90ebb844.tar.gz |
add details in bad status exception
-rw-r--r-- | websocket/_exceptions.py | 3 | ||||
-rw-r--r-- | websocket/_handshake.py | 3 |
2 files changed, 4 insertions, 2 deletions
diff --git a/websocket/_exceptions.py b/websocket/_exceptions.py index 811d594..15bbdea 100644 --- a/websocket/_exceptions.py +++ b/websocket/_exceptions.py @@ -66,11 +66,12 @@ class WebSocketBadStatusException(WebSocketException): WebSocketBadStatusException will be raised when we get bad handshake status code. """ - def __init__(self, message, status_code, status_message=None, resp_headers=None): + def __init__(self, message, status_code, status_message=None, resp_headers=None, resp_body=None): msg = message % (status_code, status_message) super().__init__(msg) self.status_code = status_code self.resp_headers = resp_headers + self.resp_body = resp_body class WebSocketAddressException(WebSocketException): diff --git a/websocket/_handshake.py b/websocket/_handshake.py index 07a4cfb..fc8f5a5 100644 --- a/websocket/_handshake.py +++ b/websocket/_handshake.py @@ -144,7 +144,8 @@ def _get_handshake_headers(resource, url, host, port, options): def _get_resp_headers(sock, success_statuses=SUCCESS_STATUSES): status, resp_headers, status_message = read_headers(sock) if status not in success_statuses: - raise WebSocketBadStatusException("Handshake status %d %s", status, status_message, resp_headers) + response_body = sock.recv(int(resp_headers['content-length'])) # read the body of the HTTP error message response and include it in the exception + raise WebSocketBadStatusException("Handshake status {status} {message} -+-+- {headers} -+-+- {body}".format(status = status, message = status_message, headers = resp_headers, body = response_body), status, status_message, resp_headers, response_body) return status, resp_headers |