question

JonathanMerican-6212 avatar image
0 Votes"
JonathanMerican-6212 asked romungi-MSFT commented

Bing Search API returns Bing Search API returns

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)

azure-cognitive-servicesazure-bing-news
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

romungi-MSFT avatar image
0 Votes"
romungi-MSFT answered romungi-MSFT commented

@JonathanMerican-6212 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.


· 3
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.

Hi Thank you very much for your response. I pip installed azure-cognitiveservices-search-newssearch into anaconda prompt and tried running ' from azure.cognitiveservices.search.newssearch import NewsSearchClient ' but i got this error ImportError: cannot import name 'NewsSearchClient' from 'azure.cognitiveservices.search.newssearch' .

0 Votes 0 ·

Hi I used your code and my endpoint is 'https://api.bing.microsoft.com/' this returned the error ErrorResponseException: Operation returned an invalid status code 'Bad Request'

0 Votes 0 ·
romungi-MSFT avatar image romungi-MSFT JonathanMerican-6212 ·

@JonathanMerican-6212 Apologies, I can confirm that the above client uses an older endpoint i.e endpoint which was supported by Azure cognitive services. Using the new endpoint https://api.bing.com/v7.0/news breaks the client. The only option available for now is to use the REST API directly.



0 Votes 0 ·