Python kubernetes module has no attribute 'api_key'

7/31/2018

I have installed the python kubernetes module via the instructions here https://github.com/kubernetes-client/python/blob/master/kubernetes/README.md via pip install, but i still can not seem to run through their example since i get an attribute error.

Code:

from __future__ import print_function
import time
import kubernetes.client
from kubernetes.client.rest import ApiException
from pprint import pprint

# Configure API key authorization: BearerToken
kubernetes.client.configuration.api_key['authorization'] = 'YOUR_API_KEY'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# kubernetes.client.configuration.api_key_prefix['authorization'] = 'Bearer'
# create an instance of the API class
api_instance = kubernetes.client.AdmissionregistrationApi()

try:
    api_response = api_instance.get_api_group()
    pprint(api_response)
except ApiException as e:
    print("Exception when calling AdmissionregistrationApi->get_api_group: %s\n" % e)

Error:

Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    kubernetes.client.configuration.api_key['authorization'] = 'YOUR_API_KEY'
AttributeError: module 'kubernetes.client.configuration' has no attribute 'api_key'
-- BLang
kubernetes
python

2 Answers

12/24/2019

You should try this

configuration = sib_api_v3_sdk.Configuration()
configuration.api_key['api-key'] = 'YOUR_API_KEY'
-- a zEnItH
Source: StackOverflow

7/31/2018

I think need to change code little bit replace this line kubernetes.client.configuration.api_key['authorization'] = 'YOUR_API_KEY'

with

configuration = kubernetes.client.Configuration()

configuration.api_key['authorization'] = 'YOUR_API_KEY'

see here

-- Pankaj78691
Source: StackOverflow