fastai / fastbook

The fastai book, published as Jupyter Notebooks
Other
21.51k stars 8.33k forks source link

Bing Image Search - API issue #587

Open DariaSka opened 1 year ago

DariaSka commented 1 year ago

Hi! I am trying to set up my Azure account to use Bing Search API. I have already created a Bing Search v7 resource, a Bing Custom Search resource and even a Bing Cognitive Search resource, though API keys from every one of those return the same error:

HTTPError: 401 Client Error: PermissionDenied for url: https://api.bing.microsoft.com/v7.0/images/search?q=khachapuri&count=150&min_height=128&min_width=128

How do I run this example?

UPD. This code works on my local machine, but not from within the Kaggle notebook. It's basically the same:

def search_images_bing(key, term, min_sz=128, max_images=150):
    search_url = "https://api.bing.microsoft.com/v7.0/images/search"
    headers = {"Ocp-Apim-Subscription-Key" : key}

    params  = {"q": term, "license": "public", "imageType": "photo", "count": max_images, "min_height":min_sz, "min_width":min_sz}
    response = requests.get(search_url, headers=headers, params=params)
    response.raise_for_status()
    return (response.json()['value'])
DarshitSolanki04 commented 11 months ago

Hi @jph00,

Since I was using bing API key, I tried to correct the function 'search_images_bing()' and was able to fix it. If it's alright then I can create a PR for the corrected function. Please let me know.

Thanks, D