<p>I'd like to call the openshift machine api (<code>/apis/machine.openshift.io/v1beta1/machines</code>). Is there a way to do this using the <code>kubernetes</code> Python module?  I can create an api object like this:</p>
<pre><code>&gt;&gt;&gt; from kubernetes import client, config
&gt;&gt;&gt; config.load_incluster_config()
&gt;&gt;&gt; api = client.CoreV1API()
</code></pre>
<p>Of course, that's a core API client, which doesn't include native support for the <code>machine</code> api. But the object has all the endpoint and authentication information. There is a likely looking <code>api.api_client.call_api</code> method, but it doesn't seem to make use of the auth information embedded in the api_client object:</p>
<pre><code>&gt;&gt;&gt; api.api_client.call_api('/apis/machine.openshift.io/v1beta1/machines', 'GET')
[...]
kubernetes.client.rest.ApiException: (403)
Reason: Forbidden
</code></pre>
<p>I can explicitly pass in auth information, but then it doesn't seem to return any content:</p>
<pre><code>&gt;&gt;&gt; &gt;&gt;&gt; api.api_client.call_api('/apis/machine.openshift.io/v1beta1/machines', 'GET', auth_settings=api.api_client.configuration.auth_settings())
(None, 200, HTTPHeaderDict({'Audit-Id': '6f6965b5-1ad7-4c5e-ab61-343e38718ff8', 'Cache-Control': 'no-cache, private', 'Content-Type': 'application/json', 'X-Kubernetes-Pf-Flowschema-Uid': '9
5848e47-b51c-46eb-aa4f-e25130d61e09', 'X-Kubernetes-Pf-Prioritylevel-Uid': '39391d77-7b32-4aa2-93c3-9915a302d361', 'Date': 'Fri, 04 Sep 2020 19:43:59 GMT', 'Transfer-Encoding': 'chunked'}))
</code></pre>
<p>I can of course just use <code>requests</code>:</p>
<pre><code>&gt;&gt;&gt; requests.get(f'{api.api_client.configuration.host}/apis/machine.openshift.io/v1beta1/machines', verify=False, headers=api.api_client.configuration.api_key)
&lt;Response [200]&gt;
</code></pre>
<p>That works fine, but it smells like I'm going about things the wrong way. What's the correct way to make arbitrary API requests using the Python <code>kubernetes</code> module?</p>

larsks
<p>Referring from <a href="https://github.com/kubernetes-client/python/issues/528" rel="nofollow noreferrer">here</a> you could use <code>api_client.call_api</code> as below to call arbitrary APIs by passing a valid <code>BearerToken</code> which could be a service account token.</p>
<pre><code>api_client.call_api('/apis/machine.openshift.io/v1beta1/machines', 'GET', auth_settings = ['BearerToken'], response_type='json', _preload_content=False)
</code></pre>
