【问题标题】:NLU Watson API - ApiException: Error: invalid request: content is empty, Code: 400NLU Watson API - ApiException:错误:无效请求:内容为空,代码:400
【发布时间】:2021-03-14 19:15:23
【问题描述】:

我正在尝试使用 Python 和 IBM Watson API 进行名称实体识别。我以前做过,但现在遇到了一个奇怪的问题。这是similar question

ApiException: Error: invalid request: content is empty, Code: 400 , X-global-transaction-id: 9ba464a0-310b-4106-8044-0362ba1d5850

我设法仅在非常小的样本(10 篇文章)上获得了结果,但如果我增加它,我会在上面得到这个错误。

我的代码:

# Pass credentials
authenticator = IAMAuthenticator('#######################')
natural_language_understanding = NaturalLanguageUnderstandingV1(version = '2020-08-01', authenticator = authenticator)

# Create a function for extracting information, using Nick's code
def get_company_list(text):
    response = natural_language_understanding.analyze(
           language = 'en', text = text,
           features = Features(
                        entities = EntitiesOptions(sentiment = False, emotion = False)
                        # keywords = KeywordsOptions(sentiment = True, emotion = True),
                        # concepts = ConceptsOptions(limit = 50),
                        # relations = RelationsOptions(),
                        # sentiment = SentimentOptions(),
                        # semantic_roles = SemanticRolesOptions(entities = True, keywords = True),
                        # emotion = EmotionOptions(),
                        # categories = CategoriesOptions()
            )).get_result()
  company_list = [entity['text'] for entity in response['entities'] if entity['type'] == 'Company']
  time.sleep(0.1)
  return(company_list)

# Apply the function and get a list of companies and titles
company_list_text = [get_company_list(text) for text in data1000['text']]
company_list_title = [get_company_list(text) for text in data1000['title']]

然后发生错误。我也使用大学服务器来运行它,但我不确定这是一个问题。之前我在 Colab 上成功过。

【问题讨论】:

    标签: python nlp ibm-watson named-entity-recognition


    【解决方案1】:

    当空字符串或无效字符作为输入传递给 Watson NLU 时,会发生 ApiException: Error: invalid request: content is empty, Code: 400 错误。

    在分派 API 请求之前检查您的输入数据是否有缺失或无效的文本值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多