question

BillOxbury-1953 avatar image
0 Votes"
BillOxbury-1953 asked BillOxbury-1953 answered

Azure Custom Search gives error 404

I'm having trouble getting custom search (CS) to work (previously been using Google's CS with no problem).
What I did (following the documentation which generally is excellent on Azure):

  1. created Bing CS resource and got key (2 provided)

  2. created Bing instance with a few domains my search aims to cover, published, copied custom config ID

  3. went back to the CS resource page and copied the sample code (for Python) as below.

  4. Ran this code in a local Jupyter notebook, using the subscription key and custom cofig ID above.

I get error 404 'resource not found', and haven't been able to figure out what needs to change in the url string...

Any help much appreciated!!

/**/
PYTHON CODE

import json
import os
from pprint import pprint
import requests

subscriptionKey = 'BING_CUSTOM_SEARCH_SUBSCRIPTION_KEY'
endpoint = https://api.bing.microsoft.com # as specified for me on CS resource page
customConfigId = "BING_CUSTOM_CONFIG"
searchTerm = "microsoft"

url = endpoint + "/bingcustomsearch/v7.0/search?q=" + searchTerm + "&customconfig=" + customConfigId

r = requests.get(url, headers={'Ocp-Apim-Subscription-Key': subscriptionKey})
pprint(json.loads(r.text))

azure-bing-custom
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

BillOxbury-1953 avatar image
1 Vote"
BillOxbury-1953 answered

Resolved :)

The tutorial code appears to have an error:

url = endpoint + "/bingcustomsearch/v7.0/search?q=" + searchTerm + "&customconfig=" + customConfigId

should be replaced by:

url = endpoint + "/v7.0/custom/search?" + "q=" + searchTerm + "&customconfig=" + customConfigId

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.