Python kubernetes模块没有“api_key”属性

2024-05-18 13:57:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经通过pip安装通过这里的指示安装了python kubernetes模块https://github.com/kubernetes-client/python/blob/master/kubernetes/README.md,但是我似乎仍然无法运行它们的示例,因为我得到了一个属性错误。在

代码:

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)

错误:

^{pr2}$

Tags: instancekeyfromimportclientapiprefix错误
2条回答

你应该试试这个

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

我想需要稍微修改一下代码 替换此行kubernetes.client.configuration.api_key['authorization'] = 'YOUR_API_KEY'

configuration = kubernetes.client.Configuration()

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

here

相关问题 更多 >

    热门问题