<p>kubernetes client corev1api connect_get_namespaced_pod_exec fails to run for python.</p>

<p>I have checked the python version == 2.7 and pip freeze - ipaddress==1.0.22, urllib3==1.24.1 and websocket-client==0.54.0 are the versions which satisfy the requirement - as mentioned here: <a href="https://github.com/kubernetes-client/python/blob/master/README.md#hostname-doesnt-match" rel="noreferrer">https://github.com/kubernetes-client/python/blob/master/README.md#hostname-doesnt-match</a>
followed the issue on this thread - <a href="https://github.com/kubernetes-client/python/issues/36" rel="noreferrer">https://github.com/kubernetes-client/python/issues/36</a> - not much help.</p>

<p>Tried usings stream as suggested here - <a href="https://github.com/kubernetes-client/python/blob/master/examples/exec.py" rel="noreferrer">https://github.com/kubernetes-client/python/blob/master/examples/exec.py</a></p>

<p>Ran:</p>

<pre><code>api_response = stream(core_v1_api.connect_get_namespaced_pod_exec,
                      name, namespace,
                      command=exec_command,
                      stderr=True, stdin=False,
                      stdout=True, tty=False)
</code></pre>

<p>Got this error:</p>

<blockquote>
  <p>ApiException: (0)
  Reason: hostname '10.47.7.95' doesn't match either of '', 'cluster.local'</p>
</blockquote>

<p>Without stream using directly the CoreV1Api -</p>

<p>Ran :</p>

<pre><code>core_v1_api = client.CoreV1Api()
api_response = core_v1_api.connect_get_namespaced_pod_exec(name=name,namespace=namespace,command=exec_command,stderr=True, stdin=False,stdout=True, tty=False)
</code></pre>

<p>Got this error:</p>

<blockquote>
  <p>ApiException: (400)
  Reason: Bad Request
  HTTP response headers: HTTPHeaderDict({'Date': 'Sat, 05 Jan 2019 08:01:22 GMT', 'Content-Length': '139', 'Content-Type': 'application/json'})
  HTTP response body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"Upgrade request required","reason":"BadRequest","code":400}</p>
</blockquote>

<p>I wrote a simple program to check that:</p>

<pre><code>from kubernetes import client, config
from kubernetes.stream import stream

# create an instance of the API class

config.load_kube_config()
api_instance = client.CoreV1Api()

exec_command = [
    '/bin/sh',
    '-c',
    'echo This is Prafull Ladha and it is test function']
resp = stream(api_instance.connect_get_namespaced_pod_exec, "nginx-deployment-76bf4969df-467z2", 'default',
              command=exec_command,
              stderr=True, stdin=False,
              stdout=True, tty=False)
print("Response: " + resp)
</code></pre>

<p>It is working perfectly fine for me.</p>

<p>I believe you're using <code>minikube</code> for development purpose. It is not able to recognise your hostname. You can make it work by disabling <code>assert_hostname</code> in your program like:</p>

<pre><code>from kubernetes.client import configuration 
config.load_kube_config()                                                 
configuration.assert_hostname = False
</code></pre>

<p>This should resolve your issue.</p>
