02_production PermissionDenied Error

I tried the updated version from Microsoft that @Zmey56 tried, but I still get an Access Denied although all my keys are right. Any ideas?

I don’t think Access Denied is the same as Permission Denied, need more info posted on what you are doing.


As the response code from the request is not actually seen in the stack trace it would need to be found using debug. A fault is anything other than the code 200

Searching through the response codes at HTTP Response Codes there are no direct matchings for ‘PermissionDenied’ and ‘Access Denied’. They are perhaps AZURE specific. A search of the AZURE python code in


maybe fruitful.

Other than that take the advise given by the other posters in this post.

I believe Jeremy did not intend for AZURE to be the definitive image search but was left with it as a compromise. Also AZURE interface may be changed at any time, so expect new behaviour to occur.

It maybe that one relates to a good key value and some other security issue, or else a bad key and then a direct failure.

Azure status codes

This solves the Permission Denied error by building on Zmey56’s solution.
I created a local instance of the bing search function, that returns an L object.

 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)
     search_results = response.json()    
     return L(search_results['value'])

But because the old code looks for the keyname content_url, you need to change it to ‘contentUrl’

results = search_images_bing(key, 'grizzly bear', min_sz=128)
ims = results.attrgot('contentUrl')

Then it works fine and fits in nicely into the jupyter workbooks


I have been having the same issue although I changed it in the utils.py file that is installed in my notebook. Still the same issue.
It appears though it is calling another the file from following path which I cannot find to alter the code:

Can anybody help?

Very much appreciate it!

1 Like

Nah apparently not the utils.py file from the jupyter nb is taken but another one you cannot change.
I recommend implementing retuso’s solution in a cell in your notebook! :slight_smile:

I can confirm this works wonderfully and I’m grateful for the solution.
(In my case, I preferred to give this function a new name, not overwrite the initial one.)
Also, it’s very easy to forget to change content_url to contentUrl, this might first thing to look at if errors.

1 Like

This code


uses the base class


to pass the error as is returned from the server.

it does work,thank you very much

This is what I did as well, still awaiting from Microsoft whether they plan to update documentation and code for the ImageSearchClient API.

I can confirm that this works as of Nov 9 2020. Thank you.

Many thanks retuso!!
It works beautifully

1 Like

These instructions no longer work - the Bing images search is no longer in Cognitive Services - the new endpoint is https://api.bing.microsoft.com/ . I got the key by going to BingImages > Keys and Endpoint but can’t get it to work with the Fast Ai api; I get a Permission Denied error. When I try out the key using example code from Microsoft I don’t get an error.

Found solution above. Thanks so much

Same here, clearly microsoft have changed the whole image search product, and not made it backwards compatible, i’ve wasted hours on this. :frowning:

Yep! That was it! Just missed the uppercase…

Thank you!

thanks very much for your code, works really well. I am trying to learn more about you L object, but I cant find ‘L Object’ anywhere in the python documentation. Would you be able to point me in the right direction?
Thanks for your hl

Here you go

1 Like


Hi all,

As an alternative to using Bing search, @joedockrill has written a package called jmd_imagescraper that requires no license keys and is just as easy to use.


Best regards,

1 Like

This tool is fantastic, much better than the azure image API right now lol. I could not get my API keys to authenticate despite my best efforts :frowning:


I am getting no images saved in my path folder, I have used your bing search function. I am using the notebook in gradient.

1 Like