IBM Cloud-Watson NLC-TypeError:__init __()获得了意外的关键字参数'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"
okgame 回答:IBM Cloud-Watson NLC-TypeError:__init __()获得了意外的关键字参数'iam_apikey'

似乎您在Watson SDK中遇到了问题。最近,在V4中,他们引入了breaking change,我在他们的release notes中发现了它们。有一种新的,更抽象的身份验证机制可以满足不同的身份验证类型。您需要稍微更改一下如何初始化NLC的代码。

这来自migration instructions

  

例如,传递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://www.f2er.com/3083053.html

大家都在问