Chelsea
Chelsea

Reputation: 1

Invalid Clarifai API key or pair?

On Clarifai community, I created a new project and generated a new API key with scope of all. When I try to input my key as an environmental variable, I'm unable to use it. I've posted the code, warning, and error below. Trying to utilize the ClarifaiAPIImageExtractor...

from pliers.filters import FrameSamplingFilter
from pliers.extractors import ClarifaiAPIImageExtractor, merge_results

video = join(get_test_data_path(), 'video', 'small.mp4')

# Sample 2 frames per second
sampler = FrameSamplingFilter(hertz=2)
frames = sampler.transform(video)

api_key = os.environ.get('CLARIFAI_API_KEY')

ext = ClarifaiAPIImageExtractor(api_key=api_key)
results = ext.transform(frames)
df = merge_results(results, )
df

generates the following warning:

WARNING:root:b'GET https://api.clarifai.com/v2/models FAILED(1659415936.709821). status_code: 401, reason: Unauthorized, error_code: 11008, error_description: Invalid API key or Invalid API key/application pair, error_details: Invalid format of key.\n >> Python client 2.6.2 with Python 3.7.12 on darwin\n >> GET https://api.clarifai.com/v2/models\n >> REQUEST(1659415936.709821) {\n  "page": 1,\n  "per_page": 20\n}\n >> RESPONSE(1659415936.709821) {\n  "status": {\n    "code": 11008,\n    "description": "Invalid API key or Invalid API key/application pair",\n    "details": "Invalid format of key.",\n    "req_id": "1dd144af76c8fe7f2ae9a35a2204a079"\n  },\n  "models": []\n}'
0it [00:06, ?it/s]

Upvotes: 0

Views: 259

Answers (1)

Jasoya
Jasoya

Reputation: 66

It seems you've used the wrong format of the API Key. According to the Clarifai documentation, you need to authenticate this way:

# metadata = (('authorization', 'Key ' + 'YOUR_CLARIFAI_API_KEY_HERE'),)
# Yes, the word 'Key' appears in addition to the alphanumeric PAT or API Key

So, you need to provide the word 'Key' in addition to your API Key.

Try this:

api_key = os.environ.get('Key CLARIFAI_API_KEY_HERE')

Upvotes: 1

Related Questions