Bing Search API returns Bing Search API returns

Jonathan Merican 1 Reputation point
2022-03-11T08:56:38.96+00:00

Hi,

I have been using the bing search api on python for quite some time without any issues but recently after changing my card details on my account the api has been returning:

ErrorResponseException: Operation returned an invalid status code 'PermissionDenied'

This is my code:

from azure.cognitiveservices.search.newssearch import NewsSearchAPI
from msrest.authentication import CognitiveServicesCredentials

client = NewsSearchAPI(CognitiveServicesCredentials(subscription_key))
news_result = client.news.search(query='Sugar', market="en-us", count=10)

Bing News Search
Bing News Search
A Bing service that supports searching for news and get comprehensive results.
47 questions
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
2,587 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. romungi-MSFT 43,656 Reputation points Microsoft Employee
    2022-03-11T11:29:15.507+00:00

    @Jonathan Merican Changing the card details shouldn't actually change the keys of your resource to cause permission issues while using the API.

    With respect to the error, I see you have not set the endpoint in your call to initialize the client. You can follow these steps or lookup this snippet and add the endpoint details.

    from azure.cognitiveservices.search.newssearch import NewsSearchClient  
    from msrest.authentication import CognitiveServicesCredentials  
    subscription_key = "YOUR-SUBSCRIPTION-KEY"  
    endpoint = "YOUR-ENDPOINT"  
    search_term = "Quantum Computing"  
      
    client = NewsSearchClient(endpoint=endpoint, credentials=CognitiveServicesCredentials(subscription_key))  
      
    news_result = client.news.search(query=search_term, market="en-us", count=10)  
    

    If an answer is helpful, please click on 130616-image.png or upvote 130671-image.png which might help other community members reading this thread.