Bing Python 的图像搜索 SDK:获取 'Permission Denied'
Bing Image Search SDK for Python: Getting 'Permission Denied'
我正在尝试使用示例程序 provided by Microsoft here 来测试与他们在 Azure 上的认知服务产品相关联的 Bing 图像搜索服务。我一个字符一个字符地输入代码(当然,使用我自己的 API 键),当我执行程序时,我收到以下错误消息:
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'
我毫无疑问地知道我在程序中输入了正确的 API 密钥。我的定价等级为 S0 即用即付,但我也没有任何其他选择。这必须有一个简单的解决方案。
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!")
我刚刚测试了代码,代码没问题。因此,您必须提供错误的 API 密钥。
这是我的测试密钥52c32221ceaa4f388b26a2b85fb79bff
。这是一个 7 天免费试用密钥。我知道了 here.
我正在尝试使用示例程序 provided by Microsoft here 来测试与他们在 Azure 上的认知服务产品相关联的 Bing 图像搜索服务。我一个字符一个字符地输入代码(当然,使用我自己的 API 键),当我执行程序时,我收到以下错误消息:
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'
我毫无疑问地知道我在程序中输入了正确的 API 密钥。我的定价等级为 S0 即用即付,但我也没有任何其他选择。这必须有一个简单的解决方案。
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!")
我刚刚测试了代码,代码没问题。因此,您必须提供错误的 API 密钥。
这是我的测试密钥52c32221ceaa4f388b26a2b85fb79bff
。这是一个 7 天免费试用密钥。我知道了 here.