Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_get_resp_headers() is failing with KeyError: 'content-length' with 1.5.2 for unsuccessful response, this works with 1.5.1 #913

Closed
dbasunag opened this issue May 31, 2023 · 4 comments

Comments

@dbasunag
Copy link

This was seen with kubernetes client calls returning failure status, this is no longer raising up correct error response/status etc. and is now failing with KeyError: 'content-length' (with 1.5.2 only, works fine with 1.5.1):
Seems like with f85ae1f, this issue was introduced. Do you have any suggestions on how to work around this? Any suggestions or helps would be highly appreciated.
{noformat}
Traceback (most recent call last):
File "/.venv/lib/python3.9/site-packages/kubernetes/stream/ws_client.py", line 521, in websocket_call
client = WSClient(configuration, url, headers, capture_all)
File "/.venv/lib/python3.9/site-packages/kubernetes/stream/ws_client.py", line 65, in init
self.sock = create_websocket(configuration, url, headers)
File ".venv/lib/python3.9/site-packages/kubernetes/stream/ws_client.py", line 487, in create_websocket
websocket.connect(url, **connect_opt)
File "/.venv/lib/python3.9/site-packages/websocket/_core.py", line 253, in connect
self.handshake_response = handshake(self.sock, url, *addrs, **options)
File "/.venv/lib/python3.9/site-packages/websocket/_handshake.py", line 57, in handshake
status, resp = _get_resp_headers(sock)
File "/.venv/lib/python3.9/site-packages/websocket/_handshake.py", line 147, in _get_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
KeyError: 'content-length'

File "/.venv/lib/python3.9/site-packages/kubernetes/client/api/core_v1_api.py", line 994, in connect_get_namespaced_pod_exec
return self.connect_get_namespaced_pod_exec_with_http_info(name, namespace, **kwargs) # noqa: E501
File "/.venv/lib/python3.9/site-packages/kubernetes/client/api/core_v1_api.py", line 1101, in connect_get_namespaced_pod_exec_with_http_info
return self.api_client.call_api(
File "/.venv/lib/python3.9/site-packages/kubernetes/client/api_client.py", line 348, in call_api
return self.__call_api(resource_path, method,
File "/.venv/lib/python3.9/site-packages/kubernetes/client/api_client.py", line 180, in __call_api
response_data = self.request(
File "/.venv/lib/python3.9/site-packages/kubernetes/stream/ws_client.py", line 527, in websocket_call
raise ApiException(status=0, reason=str(e))
kubernetes.client.exceptions.ApiException: (0)
Reason: 'content-length'
{noformat}

@engn33r
Copy link
Collaborator

engn33r commented Jun 1, 2023

I suspect the issue is that this line that was added to fix #900
response_body = sock.recv(int(resp_headers['content-length']))

and the HTTP message may not have a content-length header. Could you share the HTTP message, or at least the headers, of the message that is causing the issue? Wireshark may be useful to capture it. I did not realize this header might be optional, I'll have to check the HTTP specs.

@dbasunag
Copy link
Author

dbasunag commented Jun 2, 2023

This is a get call that I am expecting to fail with 403 forbidden error.
Here is the details
header: {'audit-id': '<something>', 'cache-control': 'no-cache, private', 'content-type': 'application/json', 'strict-transport-security': 'max-age=31536000; includeSubDomains; preload', 'date': 'Fri, 02 Jun 2023 01:25:36 GMT', 'transfer-encoding': 'chunked'} status: 403 message: Forbidden

@oliviermartin
Copy link

I can see there is already a PR for this issue: #911

@engn33r
Copy link
Collaborator

engn33r commented Jun 9, 2023

This should be fixed in 1.5.3

@engn33r engn33r closed this as completed Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants