简体   繁体   中英

Python kubernetes module has no attribute 'api_key'

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'

I think need to change the code a 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

You should try this

configuration = sib_api_v3_sdk.Configuration()
configuration.api_key['api-key'] = 'YOUR_API_KEY'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM