Python: connect_get_namespaced_pod_portforward and connect_post_namespaced_pod_portforward not working

Created on 13 Dec 2017  路  17Comments  路  Source: kubernetes-client/python

Sample code:

resp = v1api.connect_post_namespaced_pod_portforward(
            test_pod.metadata.name, test_pod.metadata.namespace,
            ports=8080,
            _request_timeout=60,
            _preload_content=False
        )

HTTP 400 Upgrade request required is returned from the API server.

E           kubernetes.client.rest.ApiException: (400)
E           Reason: Bad Request
E           HTTP response headers: HTTPHeaderDict({'Cache-Control': 'no-store', 'Content-Type': 'application/json', 'Date': 'Wed, 13 Dec 2017 08:22:09 GMT', 'Content-Length': '139'})
E           HTTP response body: b'{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"Upgrade request required","reason":"BadRequest","code":400}\n'

/home/vfreex/.local/lib/python3.6/site-packages/kubernetes/client/rest.py:240: ApiException

Most helpful comment

please look at https://github.com/kubernetes-incubator/client-python/blob/master/examples/exec.py

stream only works for UTF-8 output. Anything else crashes it.

All 17 comments

please look at https://github.com/kubernetes-incubator/client-python/blob/master/examples/exec.py

stream only works for UTF-8 output. Anything else crashes it.

I'm getting the same HTTP 400 Upgrade request required response without using stream.

With stream, connect_post_namespaced_pod_exec works but connect_post_namespaced_pod_portforward returns this API exception:Reason: 'utf-8' codec can't decode byte 0xc0 in position 1: invalid start byte

This issue is still there, the example @mbohlool is sharing is for exec not for
connect_post_namespaced_pod_portforward

+1 same issue here

+1 the issue is still there , can some one please have a look and resolve it ASAP

AFAIK port forward is not supported on this client yet. The Python client is a silver client.

@mbohlool Why did you close this without any helpful comment? What does that mean "please look at"? The example given is about exec, not about portforward... I have the same problem and the link does NOT help at all.

As this is a open source project, can the folks interested in this issue organize themselves to fix this issue and open a PR? Looks like there is lot of interest. It would help the overloaded existing maintainers for sure.

not working here either, here's the sample code i tried to use

from kubernetes import client, config
from kubernetes.stream import stream

podname = "xxx-aaaa"
namespace = "demo"
localport = 52501

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

resp = stream(core.connect_get_namespaced_pod_portforward, podname, namespace, ports=localport,
              _request_timeout=60, _preload_content=False)
print(resp.read_stdout())

/reopen

@Ark-kun: You can't reopen an issue/PR unless you authored it or you are a collaborator.

In response to this:

/reopen

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

did anyone ever get this working?

AFAIK port forward is not supported on this client yet. The Python client is a silver client.

@micw523 Thank you for this helpful answer. I too believe this is the root of why this feature does not work in the python client.

Hope this is still of help: I got something working from the example at https://github.com/kubernetes-client/python/blob/master/examples/pod_portforward.py#L97

It's pretty low-level (especially from a Python point of view) but it appears to work very well. There's some more work involved if you want to inspect the response status and headers in a familiar way as well, you'd have to parse the raw response into a more manageable form.

I would recommend this approach: https://stackoverflow.com/questions/24728088/python-parse-http-response-string

please look at https://github.com/kubernetes-incubator/client-python/blob/master/examples/exec.py

stream only works for UTF-8 output. Anything else crashes it.

I included an updated link to one supplied by @mbohlool: since the Python client appears to have left incubator status

@mbohlool could you perhaps update your answer to include the updated link? It's much higher up the thread, so it's more visible to other users.

Was this page helpful?
0 / 5 - 0 ratings