Unable to obtain results with Entity Search Python library or query to REST API

Chris Diehl 1 Reputation point
2021-08-19T02:34:49.44+00:00

I just attempted my first entity search query with the Python library and by sending a query to the REST API. In both cases, I'm seeing Access Denied error messages.

Once I've spun up the resource, do I need to do something additional to access it? I've got a Jupyter notebook on my local machine from which I'm trying to query entity search.

Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
2,645 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. romungi-MSFT 43,696 Reputation points Microsoft Employee
    2021-08-19T07:21:37.53+00:00

    @Chris Diehl Are you using the bing resource of Azure entity search? If Yes, then the subscription key of this resource with endpoint 'api.bing.microsoft.com' should work. Here is a working example to call with REST API.

    import http.client, urllib.parse  
    import json  
      
    subscriptionKey = '<your_key>'  
    host = 'api.bing.microsoft.com'  
    path = '/v7.0/search'  
    mkt = 'en-US'  
    query = 'italian restaurants near me'  
      
    params = '?mkt=' + mkt + '&q=' + urllib.parse.quote (query)  
      
    def get_suggestions ():  
        headers = {'Ocp-Apim-Subscription-Key': subscriptionKey}  
        conn = http.client.HTTPSConnection (host)  
        conn.request ("GET", path + params, None, headers)  
        response = conn.getresponse ()  
        return response.read()  
      
      
    result = get_suggestions ()  
    print (json.dumps(json.loads(result), indent=4))  
    

    If you are using the key from the cognitive service resource of bing search with this endpoint then this error is possible. All bing search resources from cognitive services used a different endpoint and will error out.