<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>I ran into a similar problem with executing on a pod and found a solution.
I guess it could work for you as well.</p>
<ol>
<li>add the parameter _preload_content=False, to the stream call -&gt; you receive a WSClient object</li>
<li>call run_forever(timeout=10) on it</li>
<li>Then you get the correct and unformatted string with .read_stdout()</li>
</ol>
<p>For example:</p>
<pre><code>wsclient_obj = stream(v1.connect_get_namespaced_pod_exec, m
                    y_name,
                    'default',
                    command=['/bin/sh', '-c', 'echo $MY_VAR'],
                    stderr=True,
                    stdin=False,
                    stdout=True,
                    tty=False,
                    _preload_content=False
                )
wsclient_obj.run_forever(timeout=10)
response_str = wsclient_obj.read_stdout()
</code></pre>
<p>After that <code>json.loads(response_str)</code> will work :)</p>
