Jan-21-2017, 05:34 AM
import http.client, urllib.request, urllib.parse, urllib.error, base64
headers = {
# Request headers
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': '{subscription key}',
}
params = urllib.parse.urlencode({
# Request parameters
'numberOfLanguagesToDetect': '{integer}',
})
body={
"documents": [
{
"id": "string",
"text": "string"
}
]
}
try:
conn = http.client.HTTPSConnection('westus.api.cognitive.microsoft.com')
conn.request("POST", "/text/analytics/v2.0/languages?%s" % params, str(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)iam new to python and json.I want to know whether body object used in the code is a json object or a python object.
