My apologies, I posted this as a continuation of issue #138 but noticed afterwards that it was closed, so I'm posting this a new issue.
I am able to successfully execute the connect_get_namespaced_pod_exec() function on my local minikube instance. But when I run the same script against my Google GKE instance, I receive the following error:
websocket._exceptions.WebSocketBadStatusException: Handshake status 404
I have included "assert_hostname = False" as per the recommendation on #138 . And am able to connect and run other queries against my GKE instance's API server (like like list pods, list namespaces, etc).
Any help would be greatly appreciated. I've included my sample script below along with the error trace. Thanks.
-----Sample script --------------
from kubernetes import client, config
config.load_kube_config()
client.Configuration().assert_hostname=False
v1=client.CoreV1Api()
resp = v1.connect_get_namespaced_pod_exec('hello-minikube-3015430129-6spcw', 'default',
command='ls',
stderr=False, stdin=False,
stdout=False, tty=False)
print ("resp: %s" % resp)
------- Error ---------------------------
Traceback (most recent call last):
File "/home/pat/dev/python/kube/lib/python3.5/site-packages/kubernetes/client/ws_client.py", line 231, in websocket_call
client = WSClient(configuration, url, headers)
File "/home/pat/dev/python/kube/lib/python3.5/site-packages/kubernetes/client/ws_client.py", line 63, in init
self.sock.connect(url, header=header)
File "/home/pat/dev/python/kube/lib/python3.5/site-packages/websocket/_core.py", line 214, in connect
self.handshake_response = handshake(self.sock, addrs, *options)
File "/home/pat/dev/python/kube/lib/python3.5/site-packages/websocket/_handshake.py", line 65, in handshake
status, resp = _get_resp_headers(sock)
File "/home/pat/dev/python/kube/lib/python3.5/site-packages/websocket/_handshake.py", line 122, in _get_resp_headers
raise WebSocketBadStatusException("Handshake status %d", status)
websocket._exceptions.WebSocketBadStatusException: Handshake status 404
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "podExec.py", line 10, in
stdout=False, tty=False)
File "/home/pat/dev/python/kube/lib/python3.5/site-packages/kubernetes/client/apis/core_v1_api.py", line 907, in connect_get_namespaced_pod_exec
(data) = self.connect_get_namespaced_pod_exec_with_http_info(name, namespace, **kwargs)
File "/home/pat/dev/python/kube/lib/python3.5/site-packages/kubernetes/client/apis/core_v1_api.py", line 1012, in connect_get_namespaced_pod_exec_with_http_info
collection_formats=collection_formats)
File "/home/pat/dev/python/kube/lib/python3.5/site-packages/kubernetes/client/api_client.py", line 329, in call_api
_return_http_data_only, collection_formats, _preload_content, _request_timeout)
File "/home/pat/dev/python/kube/lib/python3.5/site-packages/kubernetes/client/api_client.py", line 153, in __call_api
_request_timeout=_request_timeout)
File "/home/pat/dev/python/kube/lib/python3.5/site-packages/kubernetes/client/api_client.py", line 355, in request
headers=headers)
File "/home/pat/dev/python/kube/lib/python3.5/site-packages/kubernetes/client/ws_client.py", line 237, in websocket_call
raise ApiException(status=0, reason=str(e))
kubernetes.client.rest.ApiException: (0)
Reason: Handshake status 404
Yeah I think I know what your issue is as I faced it as well. You are setting the assert_hostname on the client instead of the configuration look at exec example to get a better idea as to how to load and setup the configuration.
Edit:
Example:
from kubernetes import config
from kubernetes.client import configuration
from kubernetes.client.apis import core_v1_api
config.load_kube_config()
configuration.assert_hostname = False
api = core_v1_api.CoreV1Api()
That did the trick. Thank you!
By the way, thanks also for pointing out the code sample in the examples folder. They were very helpful.
Awesome, great that I was able to help out! And thank @mbohlool for the examples.
Yes a big thank you as well to @mbohlool for the examples and all the hard work you've put into this API.
@mrmcmuffinz I am very new to Kubernetes, can you please help me out
import kubernetes
import pydash
import kubernetes.client
from kubernetes.client.rest import ApiException
from aerolib.core import log4py
from kubernetes.stream import stream
class KuberneteClient:
def __init__(self, config_object):
configuration = kubernetes.client.Configuration()
configuration.assert_hostname = False
print('----------configuration----------------', configuration.__dict__)
self.core_client = kubernetes.client.CoreV1Api(
kubernetes.client.ApiClient(configuration))
print('------------self.core_client-------------', self.core_client)
config_object = {'username':'xxxxx','password':xxxxxx,'clustername':'xxxx','endpoint':'xxxx','authType':'xxxx'}
kube_client = KuberneteClient(config_object)
response = kube_client.connect_get_namespaced_pod_exec(
name='xxxxx',
namespace='xxxxx',
command='xxxxx',
stderr=True,
stdin=False,
stdout=True,
tty=False
)
print('-----------response--------------', response)
getting following error:
Reason: Handshake status 404 Not Found
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/kubernetes/stream/ws_client.py", line 249, in websocket_call
client = WSClient(configuration, get_websocket_url(url), headers)
File "/usr/local/lib/python3.6/site-packages/kubernetes/stream/ws_client.py", line 72, in __init__
self.sock.connect(url, header=header)
File "/usr/local/lib/python3.6/site-packages/websocket/_core.py", line 223, in connect
self.handshake_response = handshake(self.sock, addrs, *options)
File "/usr/local/lib/python3.6/site-packages/websocket/_handshake.py", line 79, in handshake
status, resp = _get_resp_headers(sock)
File "/usr/local/lib/python3.6/site-packages/websocket/_handshake.py", line 152, in _get_resp_headers
raise WebSocketBadStatusException("Handshake status %d %s", status, status_message)
websocket._exceptions.WebSocketBadStatusException: Handshake status 404 Not Found
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/celery/aero-workflow/aerolib/core/kubernetes_client.py", line 2856, in pod_exe_command
tty=False)
File "/usr/local/lib/python3.6/site-packages/kubernetes/stream/stream.py", line 32, in stream
return func(args, *kwargs)
File "/usr/local/lib/python3.6/site-packages/kubernetes/client/apis/core_v1_api.py", line 835, in connect_get_namespaced_pod_exec
(data) = self.connect_get_namespaced_pod_exec_with_http_info(name, namespace, *kwargs)
File "/usr/local/lib/python3.6/site-packages/kubernetes/client/apis/core_v1_api.py", line 935, in connect_get_namespaced_pod_exec_with_http_info
collection_formats=collection_formats)
File "/usr/local/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 321, in call_api
_return_http_data_only, collection_formats, _preload_content, _request_timeout)
File "/usr/local/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 155, in __call_api
_request_timeout=_request_timeout)
File "/usr/local/lib/python3.6/site-packages/kubernetes/stream/stream.py", line 27, in _intercept_request_call
return ws_client.websocket_call(config, *args, *kwargs)
File "/usr/local/lib/python3.6/site-packages/kubernetes/stream/ws_client.py", line 255, in websocket_call
raise ApiException(status=0, reason=str(e))
kubernetes.client.rest.ApiException: (0)
Reason: Handshake status 404 Not Found
Most helpful comment
Yes a big thank you as well to @mbohlool for the examples and all the hard work you've put into this API.