Search code examples
pythonpytorchfast-ai

Fast.ai Course 2020: HTTPError: 401 Client Error: PermissionDenied for url


I am going through the fast.ai course (version 2020) and am currently in lesson 2.

When trying to use the azure key, I always get this error and I can't figure out what to do:

#To download images with Bing Image Search, sign up at Microsoft Azure for a free account. You will be given a key, which you can copy and enter in a cell as follows (replacing 'XXX' with your key and executing it):

key = os.environ.get('AZURE_SEARCH_KEY', 'XXX')

#Once you've set key, you can use search_images_bing. This function is provided by the small utils class included with the notebooks online. If you're not sure where a function is defined, you can just type it in your notebook to find out:

search_images_bing

results = search_images_bing(key, 'grizzly bear')
ims = results.attrgot('content_url')
len(ims)


HTTPError                                 Traceback (most recent call last)
<ipython-input-18-cddb73f3292e> in <module>()
----> 1 results = search_images_bing(key, 'grizzly bear')
      2 ims = results.attrgot('content_url')
      3 len(ims)
1 frames
/usr/local/lib/python3.6/dist-packages/requests/models.py in raise_for_status(self)
    939 
    940         if http_error_msg:
--> 941             raise HTTPError(http_error_msg, response=self)
    942 
    943     def close(self):
HTTPError: 401 Client Error: PermissionDenied for url: 
https://api.bing.microsoft.com/v7.0/images/search? 
q=grizzly+bear&count=150&min_height=128&min_width=128

I am using Google Colab.

Maybe I have to add that I don't know what the key name is that I should replace the 'XXX' with. Jeremy Howard said that you would get one when signing up to Azure, but I didn't.


Solution

  • This at first didn't work for me also, then I realized I needed to register for a different Bing Search service on Azure. Look for "Bing Search v7" in the marketplace.