python client to support json data

1,195 views
Skip to first unread message

Koren Lev

unread,
Dec 30, 2017, 6:54:48 AM12/30/17
to Kubernetes developer/contributor discussion
Hi, i am trying to get kub API responses as json data using python client, ex :
from kubernetes import client
v1 = client.CoreV1Api()
nodes_str = str(v1.list_node())
nodes_json = json.loads(nodes_str)

response is not a valid json (many special keys and functions), any idea on how to get that with python client ?

Tomasz Prus

unread,
Jan 1, 2018, 4:14:28 PM1/1/18
to Kubernetes developer/contributor discussion
Hi, this client is a standard client based on OpenAPI specification.It transforms returned objects to Python objects. You can find some examples here: https://github.com/kubernetes-incubator/client-python/tree/master/examples
If you want to get a raw JSON response from API Server it will be simpler to call API directly (from urllib, requests or other libraries).

Regards,
Tomasz Prus

Shimin Guo

unread,
Jan 1, 2018, 4:36:16 PM1/1/18
to Tomasz Prus, Kubernetes developer/contributor discussion
I believe you can add _preload_content=False to your API call and get back the raw JSON response.

--
You received this message because you are subscribed to the Google Groups "Kubernetes developer/contributor discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-dev+unsubscribe@googlegroups.com.
To post to this group, send email to kubernetes-dev@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kubernetes-dev/61d0092c-529d-4372-9a7a-51ef7a6464e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mehdy Bohlool

unread,
Jan 8, 2018, 5:55:05 PM1/8/18
to Kubernetes developer/contributor discussion
_preload_content=False is one way to do it (it will return an object not string, but you can call the appropriate method to get the raw response).

you can also add these to your code:

from kubernetes.client import ApiClient

r=v1.list_node()

rs=ApiClient().sanitize_for_serialization(r)

rsj=json.dumps(rs)


On Monday, January 1, 2018 at 1:36:16 PM UTC-8, Shimin Guo wrote:
I believe you can add _preload_content=False to your API call and get back the raw JSON response.
On Jan 1, 2018 1:14 PM, "Tomasz Prus" <tomas...@gmail.com> wrote:
Hi, this client is a standard client based on OpenAPI specification.It transforms returned objects to Python objects. You can find some examples here: https://github.com/kubernetes-incubator/client-python/tree/master/examples
If you want to get a raw JSON response from API Server it will be simpler to call API directly (from urllib, requests or other libraries).

Regards,
Tomasz Prus

--
You received this message because you are subscribed to the Google Groups "Kubernetes developer/contributor discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-de...@googlegroups.com.
To post to this group, send email to kuberne...@googlegroups.com.
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages