Python: get error "Upgrade request required" for exec command using exec with connect_get_namespaced_pod_exec

Created on 30 Apr 2018  路  4Comments  路  Source: kubernetes-client/python

Python : get error "Upgrade request required" for exec command using exec with connect_get_namespaced_pod_exec

when I create the pod with python api I can use kubectl and run the following commands successfully at linux command line:

kubectl exec secret-pod --namespace=production cat data/busybox/username
and
kubectl exec secret-pod --namespace=production cat data/busybox/password

The following python code fails with "Upgrade request required"

def _get_user_token(self):
try:
user = self.core_api_instance.connect_get_namespaced_pod_exec(name="secret-pod",
namespace="production",
command=["cat /data/busybox/username"],
stderr=True, stdin=False,
stdout=True, tty=False)
pprint(user)
except ApiException as e:
print("Exception when calling CoreV1Api->get_namespaced_pod_exec: %s\n" % e)

    exec_cmd = ['cat /data/busybox/password']
    try:
        passwd = self.core_api_instance.connect_get_namespaced_pod_exec(name="secret-pod",
                                                                        namespace='production',
                                                                        command=["cat /data/busybox/password"],
                                                                        stderr=True, stdin=False,
                                                                        stdout=True, tty=False)
        pprint(passwd)
    except ApiException as e:
        print("Exception when calling CoreV1Api->get_namespaced_pod_exec: %s\n" % e)

    return {'user': user, 'password': passwd}

Most helpful comment

This is fixed by using a stream:
code change:

user_name_str = stream(self.core_api_instance.connect_get_namespaced_pod_exec, name,
namespace,command=exec_command1, stderr=True, stdin=False,
stdout=True, tty=False)

All 4 comments

I upgraded kubernetes python package from 4.0.0 to 6.0.0 and websocket-client to 0.47.0 and it did not fix this

This is fixed by using a stream:
code change:

user_name_str = stream(self.core_api_instance.connect_get_namespaced_pod_exec, name,
namespace,command=exec_command1, stderr=True, stdin=False,
stdout=True, tty=False)

Is there an example for stream with tty? to emulate kubectl exec -ti

@adubkov Examples are at https://github.com/kubernetes-client/python/blob/master/examples/exec.py where interestingly enough the one that runs interactively works for me, the one that does not hangs for me.

Was this page helpful?
0 / 5 - 0 ratings