Python fast.ai seach_images_bing投掷许可被拒绝错误

Python fast.ai seach_images_bing投掷许可被拒绝错误,python,jupyter,bing,fast-ai,Python,Jupyter,Bing,Fast Ai,我正在快速跟进。ai在Gradient GPU服务器上的jupyter笔记本教程。在第二个笔记本02\u production.ipynb中,search\u images\u bing失败 代码: 错误: --------------------------------------------------------------------------- ErrorResponseException Traceback (most recent call

我正在快速跟进。ai在Gradient GPU服务器上的jupyter笔记本教程。在第二个笔记本
02\u production.ipynb
中,
search\u images\u bing
失败

代码:

错误:

---------------------------------------------------------------------------
ErrorResponseException                    Traceback (most recent call last)
<ipython-input-107-8c0a1d6b3765> in <module>
----> 1 results = search_images_bing(key, 'grizzly bear', min_sz=128)
      2 ims = results.attrgot('content_url')
      3 
      4 # ims = search_bing_by_term('grizzly bear', 100)
      5 len(ims)

/opt/conda/envs/fastai/lib/python3.8/site-packages/fastbook/__init__.py in search_images_bing(key, term, min_sz)
     50 def search_images_bing(key, term, min_sz=128):
     51     client = api('https://api.cognitive.microsoft.com', auth(key))
---> 52     return L(client.images.search(query=term, count=150, min_height=min_sz, min_width=min_sz).value)
     53 
     54 def plot_function(f, tx=None, ty=None, title=None, min=-2, max=2, figsize=(6,4)):

/opt/conda/envs/fastai/lib/python3.8/site-packages/azure/cognitiveservices/search/imagesearch/operations/_images_operations.py in search(self, query, accept_language, user_agent, client_id, client_ip, location, aspect, color, country_code, count, freshness, height, id, image_content, image_type, license, market, max_file_size, max_height, max_width, min_file_size, min_height, min_width, offset, safe_search, size, set_lang, width, custom_headers, raw, **operation_config)
    489 
    490         if response.status_code not in [200]:
--> 491             raise models.ErrorResponseException(self._deserialize, response)
    492 
    493         deserialized = None

ErrorResponseException: Operation returned an invalid status code 'PermissionDenied'
---------------------------------------------------------------------------
ErrorResponseException回溯(最近一次调用)
在里面
---->1个结果=搜索图片(关键字“灰熊”,min_sz=128)
2 ims=results.attrgot('content\u url'))
3.
4 35; ims=按搜索词搜索(灰熊,100)
5级(国际监测系统)
/opt/conda/envs/fastai/lib/python3.8/site packages/fastbook/_________.py in search_images_bing(关键字、术语、最小值)
50 def搜索图像(关键字、术语、最小值=128):
51客户端=api('https://api.cognitive.microsoft.com,auth(键))
--->52返回L(client.images.search(query=term,count=150,minu-height=minu-sz,minu-width=minu-sz).value)
53
54 def plot_函数(f,tx=None,ty=None,title=None,min=-2,max=2,figsize=(6,4)):
/搜索中的opt/conda/envs/fastai/lib/python3.8/site-packages/azure/cognitiveservices/search/imagesearch/operations//u images\u operations.py(自我、查询、接受语言、用户代理、客户端id、客户端ip、位置、外观、颜色、国家代码、计数、新鲜度、高度、id、图像内容、图像类型、许可证、市场、最大文件大小、最大高度、最大宽度、最小文件大小、最小高度、最小宽度、偏移量、安全搜索、大小、设置长度、宽度、自定义标题、原始数据、**操作配置)
489
490如果response.status_代码不在[200]中:
-->491提出模型。错误响应异常(自我反序列化,响应)
492
493反序列化=无
ErrorResponseException:操作返回无效的状态代码“PermissionDenied”
我已经在Azure/Bing.Search.v7/F1(免费层)上注册并正确设置了API,并获得了密钥


如何通过与bing API对话克服此错误?

最新版本的bing搜索似乎中断了与fast.ai的
搜索图像\u bing
功能的连接

改进了这里的一个变通方法,我能够创建一个搜索功能的本地实例,它(几乎)完全适合笔记本其余部分的自然使用

本地功能:

def search_images_bing(key, term, max_images: int = 100, **kwargs):    
    params = {'q':term, 'count':max_images}
    headers = {"Ocp-Apim-Subscription-Key":key}
    search_url = "https://api.bing.microsoft.com/v7.0/images/search"
    response = requests.get(search_url, headers=headers, params=params)
    response.raise_for_status()
    search_results = response.json() 
   
    # returns an L object to be identical to the original function.
    return L(search_results['value'])
代码调用函数,注意新的bing API没有使用原始的content\u url标记,而是使用contentUrl

# fits in nicely with the original code
results = search_images_bing(key, 'grizzly bear', min_sz=128)
ims = results.attrgot('contentUrl')
注意:我还没有使用min_sz参数

# fits in nicely with the original code
results = search_images_bing(key, 'grizzly bear', min_sz=128)
ims = results.attrgot('contentUrl')