Friday 20 September 2019

MS API

#Copyright (c) Microsoft Corporation. All rights reserved.
#Licensed under the MIT License.

# -*- coding: utf-8 -*-

import http.client, urllib.parse, json

# **********************************************
# *** Update or verify the following values. ***
# **********************************************

# Replace the subscriptionKey string value with your valid subscription key.
subscriptionKey = 'a8ad3c49b5224ff382cc138a0a52862b'

host = 'api.cognitive.microsoft.com'
path = '/bing/v7.0/Suggestions'

mkt = 'en-US'
query = 'BML'

params = '?mkt=' + mkt + '&q=' + query

def get_suggestions ():
    "Gets Autosuggest results for a query and returns the information."

    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))

1 comment:

  1. Clarity of concepts in Pass4sure Checkpoint dumps is really praiseworthy. I have used this dumps material for the preparation of my Checkpoint exam. Dumpspass4sure helped me in all possible ways to get succeeded in my dream certification. Pass4sure Checkpoint dumps pdf helped me to ace my exam.

    ReplyDelete