IBM Cloud-Watson NLC - TypeError: __init__() got an unexpected keyword argument 'iam_apikey'

无人久伴 提交于 2020-07-07 07:33:28

问题


I am currently trying to deploy an application from a repo. (https://github.com/IBM/nlc-icd10-classifier#run-locally) But it gives me this error:

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'

I am on 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"

回答1:


It seems that you ran into an issue with the Watson SDK. Recently, with V4, they introduced a breaking change which I found in their release notes. There is a new, more abstract authentication mechanism that caters to different authentication types. You would need to slightly change the code for how NLC is initialized.

This is from the migration instructions:

For example, to pass a IAM apikey:

Before

from ibm_watson import MyService

service = MyService(
    iam_apikey='{apikey}',
    url='{url}'
)

After(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://stackoverflow.com/questions/58909463/ibm-cloud-watson-nlc-typeerror-init-got-an-unexpected-keyword-argument

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!