【问题标题】:Invalid API key/application pair–Clarifai无效的 API 密钥/应用程序对——Clarifai
【发布时间】:2020-09-19 03:36:33
【问题描述】:

我正在阅读文档并想在 pycharm 中试用 api。所以我复制了代码,它告诉我我有一个“无效的 API 密钥/应用程序对”。我直接从我在https://portal.clarifai.com/ 上创建的应用程序中复制了我的 Api 密钥并将其放入。

我的代码实际上是一个完全相同的副本,除了 api 密钥被删除了我直接从我的应用程序复制的代码被删除了,我在 pycharm 上运行它。

`

from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_pb2, status_code_pb2

# Construct one of the channels you want to use
channel = ClarifaiChannel.get_json_channel()
channel = ClarifaiChannel.get_insecure_grpc_channel()

# Note: You can also use a secure (encrypted) ClarifaiChannel.get_grpc_channel() however
# it is currently not possible to use it with the latest gRPC version

stub = service_pb2_grpc.V2Stub(channel)

# This will be used by every Clarifai endpoint call.
metadata = (('authorization', 'Key {9f3d8b8ea01245e6b61c2a1311622db1}'),)
# Insert here the initialization code as outlined on this page:
# https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions

post_inputs_response = stub.PostInputs(
    service_pb2.PostInputsRequest(
        inputs=[
            resources_pb2.Input(
                data=resources_pb2.Data(
                    image=resources_pb2.Image(
                        url="https://samples.clarifai.com/metro-north.jpg",
                        allow_duplicate_url=True
                    )
                )
            )
        ]
    ),
    metadata=metadata
)

if post_inputs_response.status.code != status_code_pb2.SUCCESS:
    raise Exception("Post inputs failed, status: " + post_inputs_response.status.description)

`

【问题讨论】:

标签: python api pycharm clarifai


【解决方案1】:

Philip,您的元数据声明不正确。您没有将 API 密钥放入 {}

# This will be used by every Clarifai endpoint call.
metadata = (('authorization', 'Key {9f3d8b8ea01245e6b61c2a1311622db1}'),)

最后多了一个},请调整到这个

metadata = (('authorization', 'Key 9f3d8b8ea01245e6b61c2a1311622db1'),)

【讨论】:

    【解决方案2】:

    您能否尝试生成一个新的 API 密钥并尝试一下。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-04
      • 2012-06-15
      • 2019-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-01
      相关资源
      最近更新 更多