IBM Cloud-Watson NLC - TypeError: __init__() got an unexpected keyword argument 'iam_apikey'
IBM Cloud-Watson NLC - TypeError: __init__() got an unexpected keyword argument 'iam_apikey'
我目前正在尝试从存储库部署应用程序。 (https://github.com/IBM/nlc-icd10-classifier#run-locally) 但它给了我这个错误:
Traceback (most recent call last):
File "app.py", line 34, in <module>
iam_apikey=nlc_iam_apikey
TypeError: __init__() got an unexpected keyword argument 'iam_apikey'
我在 Python 3.6.8
app.py:
load_dotenv(os.path.join(os.path.dirname(__file__), ".env"))
nlc_username = os.environ.get("NATURAL_LANGUAGE_CLASSIFIER_USERNAME")
nlc_password = os.environ.get("NATURAL_LANGUAGE_CLASSIFIER_PASSWORD")
nlc_iam_apikey = os.environ.get("NATURAL_LANGUAGE_CLASSIFIER_IAM_APIKEY")
classifier_id = os.environ.get("CLASSIFIER_ID")
# Use provided credentials from environment or pull from IBM Cloud VCAP
if nlc_iam_apikey != "placeholder":
NLC_SERVICE = NaturalLanguageClassifierV1(
iam_apikey=nlc_iam_apikey
)
elif nlc_username != "placeholder":
NLC_SERVICE = NaturalLanguageClassifierV1(
username=nlc_username,
password=nlc_password
.env:
CLASSIFIER_ID=<add_NLC_classifier_id>
#NATURAL_LANGUAGE_CLASSIFIER_USERNAME=<add_NLC_username>
#NATURAL_LANGUAGE_CLASSIFIER_PASSWORD=<add_NLC_password>
NATURAL_LANGUAGE_CLASSIFIER_IAM_APIKEY="placeholderapikeyforstackoverflolw"
您 运行 似乎遇到了 Watson SDK 的问题。最近,在 V4 中,他们引入了 breaking change which I found in their release notes。有一种新的、更抽象的身份验证机制可以适应不同的身份验证类型。您需要稍微更改 NLC 初始化方式的代码。
这是来自 migration instructions:
For example, to pass a IAM apikey:
之前
from ibm_watson import MyService
service = MyService(
iam_apikey='{apikey}',
url='{url}'
)
之后(V4.0)
from ibm_watson import MyService
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
authenticator = IAMAuthenticator('{apikey}')
service = MyService(
authenticator=authenticator
)
service.set_service_url('{url}')
我目前正在尝试从存储库部署应用程序。 (https://github.com/IBM/nlc-icd10-classifier#run-locally) 但它给了我这个错误:
Traceback (most recent call last):
File "app.py", line 34, in <module>
iam_apikey=nlc_iam_apikey
TypeError: __init__() got an unexpected keyword argument 'iam_apikey'
我在 Python 3.6.8
app.py:
load_dotenv(os.path.join(os.path.dirname(__file__), ".env"))
nlc_username = os.environ.get("NATURAL_LANGUAGE_CLASSIFIER_USERNAME")
nlc_password = os.environ.get("NATURAL_LANGUAGE_CLASSIFIER_PASSWORD")
nlc_iam_apikey = os.environ.get("NATURAL_LANGUAGE_CLASSIFIER_IAM_APIKEY")
classifier_id = os.environ.get("CLASSIFIER_ID")
# Use provided credentials from environment or pull from IBM Cloud VCAP
if nlc_iam_apikey != "placeholder":
NLC_SERVICE = NaturalLanguageClassifierV1(
iam_apikey=nlc_iam_apikey
)
elif nlc_username != "placeholder":
NLC_SERVICE = NaturalLanguageClassifierV1(
username=nlc_username,
password=nlc_password
.env:
CLASSIFIER_ID=<add_NLC_classifier_id>
#NATURAL_LANGUAGE_CLASSIFIER_USERNAME=<add_NLC_username>
#NATURAL_LANGUAGE_CLASSIFIER_PASSWORD=<add_NLC_password>
NATURAL_LANGUAGE_CLASSIFIER_IAM_APIKEY="placeholderapikeyforstackoverflolw"
您 运行 似乎遇到了 Watson SDK 的问题。最近,在 V4 中,他们引入了 breaking change which I found in their release notes。有一种新的、更抽象的身份验证机制可以适应不同的身份验证类型。您需要稍微更改 NLC 初始化方式的代码。
这是来自 migration instructions:
For example, to pass a IAM apikey:
之前
from ibm_watson import MyService
service = MyService(
iam_apikey='{apikey}',
url='{url}'
)
之后(V4.0)
from ibm_watson import MyService
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
authenticator = IAMAuthenticator('{apikey}')
service = MyService(
authenticator=authenticator
)
service.set_service_url('{url}')