02_production PermissionDenied Error

key = ‘XXX’


results = search_images_bing(key, ‘grizzly bear’)
ims = results.attrgot(‘content_url’)

ErrorResponseException Traceback (most recent call last)
----> 1 results = search_images_bing(key, ‘grizzly bear’)
2 ims = results.attrgot(‘content_url’)
3 len(ims)

~/fastai-2020/fastai2/course-v4/nbs/utils.py in search_images_bing(key, term, min_sz)
31 def search_images_bing(key, term, min_sz=128):
32 client = api(‘https://api.cognitive.microsoft.com’, auth(key))
—> 33 return L(client.images.search(query=term, count=150, min_height=min_sz, min_width=min_sz).value)

~/anaconda3/envs/fastai2/lib/python3.7/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)
490 if response.status_code not in [200]:
–> 491 raise models.ErrorResponseException(self._deserialize, response)
493 deserialized = None

ErrorResponseException: Operation returned an invalid status code ‘PermissionDenied’


To use Image Search on Bing, you need a key from Microsoft: https://azure.microsoft.com/en-us/services/cognitive-services/bing-image-search-api/ (requires a credit card from what I can see)

Once you are registered, you should replace the XXX with your actual key.


@zerotosingularity I am having the same issue, even after I activated the cognitive service account and create the resource

1 Like

@Albertotono Did you run again [5] after modifying it with your key?

Yes, I change the variable and then I run the code. With my Key1 in the API

1 Like

My error was ‘PermissionDenied’, yours is ‘Access Denied’ which maybe a different issue.

To handle the key as they are long and can easily be typed incorrectly is to

In you ~/.bashrc file add
export AZURE_SEARCH_KEY=a big long number

then in the notebook cell use

key = os.environ(“AZURE_SEARH_KEY”)

That’s for Ubuntu for others you have to modify accordingly

I think if my memory holds up, that you have to make a copy/exact note of this key for once you leave the page you created it in you cannot access it again … ever

I’ll have to register myself when I go through the lessen… Or have you fixed the problem in the meantime?

Same issue here. My output is also ‘PermissionDenied’. This is after I inserted my key. I also got same response after restarting kernal and also logging out and back in again.



Make sure you are registering for a Bing Search resource as well - https://azure.microsoft.com/en-us/pricing/details/cognitive-services/search-api/

After I registered for Azure I searched for “Bing Search” at the top. The only option under Marketplace is what you want. Register again. I picked the free option F1. Then click on ‘Go to resource’. And theres the key that you need.

This link should also show you your keys - https://azure.microsoft.com/en-us/try/cognitive-services/my-apis/ at the bottom


I am still getting error as below :
ErrorResponseException: Operation returned an invalid status code ‘Access Denied’

IF anyone had success accessing the imagest via ImageSearchAPI, please help

Is it possible that you signed up for the wrong service???


Follow the instructions here: https://helpcenterhq.com/knowledgebase.php?article=189

Make sure you are getting the key for Bing Search APIs v7 and and not other service like computer vision or something else also ensure This API key is currently active


Thank you I was using the wrong tier. corrected it and not i can access the data. Thank you all :smile: !

After having successfully run 02_production a few days ago, I now get "Operation returned an invalid status code ‘PermissionDenied’ " after I’ve done a git pull, and am attempting to run the notebook. (Note: I had actually created a copy of 02_production and was seeing the error there, so I thought I’d try the original too. Same error)

Anyone else seeing this? One thought is that the azure key may have expired, though I’m unable to find if it has any expiration. Does it?

EDIT and SOLUTON – It looks like it does expire after a week. Then they ask you to sign up with some options:

I found that you can use any name for Name* and for Resource Group. You just click the ‘create’ button next to Resource Group and it allows you to create a new one, enter new information. Then you get to this screen after a couple of minutes:

Screen Shot 2020-04-05 at 12.39.32 PM

I assume that this begins using the $200 credit that they offer.


I also had the same problem with permission, due to wrong service added.

The easiest way to check if you have the right service is through this link:

There you can see:

  • what you have currently signed up to
  • your api keys
  • the expiry time of the service

below this section there is also a " You might also be interested in" section.
There you can find the image search if it is missing. Simply click the “add” button below option(s) of choice.

1 Like

This was generally helpful thank you. In case I’m not the only one with this issue even after thinking I went through all the above steps correctly, pointing me to the “You might also be interested in” section and showing all led me to fix it.

My problem was I had the Bing Search APIs, but there is apparently a difference between the regular Bing Search API, and Bing Search APIs v7. Adding the v7 one fixed it for me. Adding screenshot below for clarity.


I was trying to use Computer Vision, but using Search APIs v7 does work. Thanks!

I’m getting the PermissionDenied Error, too, and even Bing Search APIs v7 doesn’t help.

I think the issue is that Microsoft has changed the service from “Cognitive” to “Bing Services”, something along the lines. This started on 1/11/20.

Probably in the utils.py file the API url needs to be changed from https://api.cognitive.microsoft.com to https://api.bing.microsoft.com/v7.0/images/search? @jeremy

I tried the code in https://docs.microsoft.com/en-us/bing/search-apis/bing-image-search/quickstarts/rest/python and that worked for the API and that’s where I get the link from.


I tried change, but I got error: Operation returned an invalid status code ‘Resource Not Found’ and I have problem with PermissionDenied. I can’t solve it.

I solved this problem with code:

And now I have 450 imges bears