@Crystal Welcome to Microsoft Q&A Forum, Thank you for posting your query here!
I was able to use the below sample code and that worked fine. Please update the subscription_key
and the query
in the below code and run the sample:
import json
import os
from pprint import pprint
import requests
'''
This sample makes a call to the Bing Web Search API with a query and returns relevant web search.
'''
# Add your Bing Search V7 subscription key and endpoint to your environment variables.
subscription_key = "aae3eXXXXXXXXXXXXXXXXXXXffe1c31"
endpoint = "https://api.bing.microsoft.com" + "/v7.0/search"
# Query term(s) to search for.
query = "Microsoft Azure Open AI Service"
# Construct a request
mkt = 'en-US'
params = { 'q': query, 'mkt': mkt }
headers = { 'Ocp-Apim-Subscription-Key': subscription_key }
# Call the API
try:
response = requests.get(endpoint, headers=headers, params=params)
response.raise_for_status()
print("\nHeaders:\n")
print(response.headers)
print("\nJSON Response:\n")
pprint(response.json())
except Exception as ex:
raise ex
Hope this helps. If you have any follow-up questions, please let me know. I would be happy to help.