J'essaie d'utiliser le programme d'exemple fournie par Microsoft ici pour tester le service de recherche d'images de Bing associé à leur offre Cognitive Service sur Azure. Je tape le code caractère par caractère (en utilisant bien sûr ma propre clé API) et j'obtiens le message d'erreur ci-dessous lorsque j'exécute le programme :
Traceback (most recent call last):
File "x.py", line 9, in <module>
image_results = client.images.search(query=search_term)
File "/home/rsbrownjr/anaconda3/envs/ibing/lib/python3.6/site-packages/azure/cognitiveservices/search/imagesearch/operations/images_operations.py", line 485, in search
raise models.ErrorResponseException(self._deserialize, response)
azure.cognitiveservices.search.imagesearch.models.error_response_py3.ErrorResponseException: Operation returned an invalid status code 'PermissionDenied'
Je sais sans l'ombre d'un doute que j'ai la bonne clé API dans le programme. Je suis sur le niveau de prix S0 pay-as-you-go mais je n'ai pas d'autres options non plus. Il doit y avoir une solution simple.
from azure.cognitiveservices.search.imagesearch import ImageSearchAPI
from msrest.authentication import CognitiveServicesCredentials
subscription_key = "MY API KEY HERE"
search_term = "canadian rockies"
client = ImageSearchAPI(CognitiveServicesCredentials(subscription_key))
image_results = client.images.search(query=search_term)
if image_results.value:
first_image_result = image_results.value[0]
print("Total number of images returned: {}".format(len(image_results.value)))
print("First image thumbnail url: {}".format(
first_image_result.thumbnail_url))
print("First image content url: {}".format(first_image_result.content_url))
else:
print("No image results returned!")