Skip to content

Instantly share code, notes, and snippets.

@standbyme
Created July 20, 2017 06:07
Show Gist options
  • Save standbyme/41bf496f7e070de367dee776a86054a7 to your computer and use it in GitHub Desktop.
Save standbyme/41bf496f7e070de367dee776a86054a7 to your computer and use it in GitHub Desktop.
Python!!!!3!!!!!
import http.client
import urllib.request
import urllib.parse
import urllib.error
import base64
import json
sub_key = "ba0747d02f2a42ffbc0f0dd2cb1fba06"
KBID = "b49a4b5a-8a4e-4feb-9caa-604ea9a6ba82"
headers = {
# Request headers
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': sub_key,
}
body = {
"question": "hi",
"top": 1
}
body = json.dumps(body)
try:
conn = http.client.HTTPSConnection('westus.api.cognitive.microsoft.com')
conn.request("POST", '''/qnamaker/v2.0/knowledgebases/b49a4b5a-8a4e-4feb-9caa-604ea9a6ba82/generateAnswer''', body, headers)
response = conn.getresponse()
data = response.read()
print(data)
conn.close()
except Exception as e:
print("[Errno {0}] {1}".format(e.errno, e.strerror))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment