<p>I'm using python kubernetes 3.0.0 library and kubernetes 1.6.6 on AWS.</p>

<p>I have pods that can disappear quickly. Sometimes when I try to exec to them I get ApiException <code>Handshake status 500</code> error status.</p>

<p>This is happening with <code>in cluster configuration</code> as well as <code>kube config</code>.</p>

<p>When pod/container doesn't exist I get <code>404</code> error which is reasonable but <code>500</code> is <code>Internal Server Error</code>. I don't get any <code>500</code> errors in <code>kube-apiserver.log</code> where I do find <code>404</code> ones.</p>

<p>What does it mean and can someone point me in the right direction.</p>

<p>I know that this question is a little old, but I thought I would share what I found when trying to use python/kubernetes attach/exec for several debugging cases (since this isn't documented anywhere I can find).</p>

<p>As far as I can tell, it's all about making the keyword arguments match the actual container configuration as opposed to what you want the container to do.</p>

<p>When creating pods using <code>kubectl run</code>, if you don't use <code>-i --tty</code> flags (indicating interactive/TTY allocation), and then attempt to set either the <code>tty</code> or <code>stdin</code> flags to <code>True</code> in your function, then you'll get a mysterious 500 error with no other debug info. If you need to use <code>stdin</code> and <code>tty</code> and you are using a configuration file (as opposed to run), then make sure you <a href="https://stackoverflow.com/questions/37559704/kubectl-yaml-config-file-equivalent-of-kubectl-run-i-tty">set the <code>stdin</code> and <code>tty</code> flags to <code>true</code> in <code>spec.containers</code></a>.</p>

<p>While running <code>resp.readline_stdout()</code>, if you get a <code>OverflowError: timestamp too large to convert to C _PyTime_t</code>, set the keyword argument <code>timeout=&lt;any integer&gt;</code>. By default, the timeout variable defaults to None, which is an invalid value in that function.</p>

<p>If you run the attach/exec command and get an APIException and a status code of 0, the error <code>Reason: hostname 'X.X.X.X' doesn't match either of...</code>, note that there appears to be an incompatibility with Python 2. Works in Python 3. Should be patched eventually.</p>

<p>I can confirm 404 code is thrown via an ApiException when the pod doesn't exist.</p>

<p>If you are getting a mysterious error saying <code>upgrade request required</code>, note that you need to use the <code>kubernetes.stream.stream</code> function to wrap the call to attach/exec. You can see this <a href="https://github.com/kubernetes-client/python/issues/409" rel="noreferrer">issue on GitHub</a> and <a href="https://github.com/kubernetes-client/python/blob/master/examples/exec.py" rel="noreferrer">this example code</a> to help you get past that part.</p>

<p>Here's my example: <code>resp = kubernetes.stream.stream(k8s.connect_get_namespaced_pod_attach, name='alpine-python-2', namespace="default", stderr=True, stdin=True, stdout=True, tty=True, _preload_content=False)</code></p>

<p>Note that the <code>_preload_content=False</code> is essential in the <code>attach</code> command or else the call will block indefinitely.</p>

<p>I know that was probably more information than you wanted, but hopefully at least some of it will help you.</p>
