<p>I'm requesting some JSON data from a pod's web server via the Kubernetes API proxy verb. That is:</p>

<pre><code>corev1 = kubernetes.client.CoreV1Api()
res = corev1.connect_get_namespaced_pod_proxy_with_path(
    'mypod:5000', 'default', path='somepath', path2='somepath')
print(type(res))
print(res)
</code></pre>

<p>The call succeeds and returns a <code>str</code> containing the serialized JSON data from my pod's web service. Unfortunately, <code>res</code> now looks like this ... which isn't valid JSON at all, so <code>json.loads(res)</code> denies to parse it:</p>

<pre><code>{'x': [{'xx': 'xxx', ...
</code></pre>

<p>As you can see, the stringified response looks like a Python dictionary, instead of valid JSON. Any suggestions as to how this convert safely back into either correct JSON or a correct Python <code>dict</code>?</p>

<p>Looking at the source code for <a href="https://github.com/kubernetes-client/python/blob/master/kubernetes/client/api/core_v1_api.py" rel="nofollow noreferrer">core_v1_api.py</a>. The method calls generally accept a kwarg named <code>_preload_content</code>.</p>
<p>Setting this argument to <code>False</code> instructs the method to return the <code>urllib3.HTTPResponse</code> object instead of a processed <code>str</code>. You can then work directly with the data, which cooperates with <code>json.loads()</code>.</p>
<p>Example:</p>
<pre class="lang-py prettyprint-override"><code>corev1 = client.CoreV1Api()
res = corev1.connect_get_namespaced_pod_proxy_with_path(
    'mypod:5000', 'default', path='somepath', 
    path2='somepath', _preload_content=False)
json.loads(res.data)
</code></pre>
