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

import http.client, urllib.parse, json, time

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

# NOTE: Replace this with a valid host name.
host ="no13.azurewebsites.net"

# NOTE: Replace this with a valid endpoint key.
# This is not your subscription key.
# To get your endpoint keys, call the GET /endpointkeys method.
endpoint_key = "e0238c17-abed-4970-85e5-12115d07b73e"

# NOTE: Replace this with a valid knowledge base ID.
# Make sure you have published the knowledge base with the
# POST /knowledgebases/{knowledge base ID} method.
kb = "c5a268aa-e90c-41f0-8a37-967f765b3623"

method = "/qnamaker/knowledgebases/" + kb + "/generateAnswer"

question = {
    'question': 'Plastics bottle',
}

def pretty_print (content):
# Note: We convert content to and from an object so we can pretty-print it.
    return json.loads(content)

def get_answers (path, content):
    print ('Calling ' + host + path + '.')
    headers = {
        'Authorization': 'EndpointKey ' + endpoint_key,
        'Content-Type': 'application/json',
        'Content-Length': len (content)
    }
    conn = http.client.HTTPSConnection(host)
    conn.request ("POST", path, content, headers)
    response = conn.getresponse ()
    return response.read ()

# Convert the request to a string.
content = json.dumps(question)
result = get_answers (method, content)
print (pretty_print(result)["answers"][0]["answer"])





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

import http.client, urllib.parse, json, time

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

# NOTE: Replace this with a valid host name.
host ="no13.azurewebsites.net"

# NOTE: Replace this with a valid endpoint key.
# This is not your subscription key.
# To get your endpoint keys, call the GET /endpointkeys method.
endpoint_key = "e0238c17-abed-4970-85e5-12115d07b73e"

# NOTE: Replace this with a valid knowledge base ID.
# Make sure you have published the knowledge base with the
# POST /knowledgebases/{knowledge base ID} method.
kb = "c5a268aa-e90c-41f0-8a37-967f765b3623"

method = "/qnamaker/knowledgebases/" + kb + "/generateAnswer"

question = {
    'question': 'Plastics bottle',
}

def pretty_print (content):
# Note: We convert content to and from an object so we can pretty-print it.
    return json.loads(content)

def get_answers (path, content):
    print ('Calling ' + host + path + '.')
    headers = {
        'Authorization': 'EndpointKey ' + endpoint_key,
        'Content-Type': 'application/json',
        'Content-Length': len (content)
    }
    conn = http.client.HTTPSConnection(host)
    conn.request ("POST", path, content, headers)
    response = conn.getresponse ()
    return response.read ()

# Convert the request to a string.
content = json.dumps(question)
result = get_answers (method, content)
print (pretty_print(result)["answers"][0]["answer"])





# -*- coding: utf-8 -*- # ********************************************** # *** Update or verify the following values. *** # ********************************************** # NOTE: Replace this with a valid host name. # NOTE: Replace this with a valid endpoint key. # This is not your subscription key. # To get your endpoint keys, call the GET /endpointkeys method. # NOTE: Replace this with a valid knowledge base ID. # Make sure you have published the knowledge base with the # POST /knowledgebases/{knowledge base ID} method. # Note: We convert content to and from an object so we can pretty-print it. # Convert the request to a string.