我已经按照https://github.com/kubernetes-client/python/blob/master/kubernetes/README.md上的说明通过pip install安装了python kubernetes模块,但是由于出现属性错误,我似乎仍然无法运行它们的示例。
代码:
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)
错误:
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'
答案 0 :(得分:2)
我认为需要一点点更改代码
替换此行kubernetes.client.configuration.api_key['authorization'] = 'YOUR_API_KEY'
使用
configuration = kubernetes.client.Configuration()
configuration.api_key['authorization'] = 'YOUR_API_KEY'
请参阅here
答案 1 :(得分:0)
您应该尝试这个
configuration = sib_api_v3_sdk.Configuration()
configuration.api_key['api-key'] = 'YOUR_API_KEY'