当我 运行 代码显示 "not acceptable 406 " 我该如何修复它?

when i run the code it says "not acceptable 406 " how can i fix it?

我搜索了 IBM 云,在他们的错误处理中他们说服务器不支持这种类型的文件

from ibm_watson import PersonalityInsightsV3
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
authenticator = IAMAuthenticator('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
personality_insights = PersonalityInsightsV3(
       version='2019-10-12',
authenticator=authenticator)
personality_insights.set_service_url('https://gateway-lon.watsonplatform.net/personality-insights/api')
profile_text = open("personality.txt").read()
profile = personality_insights.profile(profile_text,"text/plain").get_result()
needs = profile["needs"]
values = profile["values"]
personality = profile["personality"]
def print_traits(traits_category_name, traits):
  print(traits_category_name + ":")
for trait in traits:
  print(trait["name"] + ": {:.3f}%".format(
trait["percentile"] * 100))
print("\n")
print_traits("Needs", needs)
print_traits("Values", values)
print_traits("Personality", personality)

this is the code

and this the output

首先让我告诉你,通过在你的问题中分享你的凭证密钥,你已经泄露了它,你应该尽快撤销。

您收到 HTTP 406 的原因是您提供了无效的 accept 类型 text/plain。如果您查看服务的 Python SDK API 文档 - https://cloud.ibm.com/apidocs/personality-insights?code=python#get-profile - 您将看到第二个参数是 accept 并且唯一有效的类型是 application/jsontext/csv.

我认为您实际上是在尝试设置 content_type,因此您需要将服务调用到 :


profile = personality_insights.profile(profile_text, accept='application/json', content_type='text/plain').get_result()