Jan-22-2017, 05:16 PM
import http.client, urllib.request, urllib.parse, urllib.error headers = { # Request headers 'Content-Type': 'application/json', 'Ocp-Apim-Subscription-Key':'##' } params = urllib.parse.urlencode({ # Request parameters 'numberOfLanguagesToDetect': '10', }) body = { "documents": [ { "language": "en", "id": "1", "text": "First document. Hello world." } ] } 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) #pydict=json.load(data) #print(pydict) conn.close() except Exception as e: print("[Errno {0}] {1}".format(e.errno, e.strerror))from the above code i get json output as:
Output:runfile('C:/Users/msamu/textanalyse.py', wdir='C:/Users/msamu')
b'{"documents":[{"id":"1","detectedLanguages":[{"name":"English","iso6391Name":"en","score":1.0}]}],"errors":[]}'
i want to print the value of the score ie 1.0 but iam not able to do it..i used dumps function to get a python dictionary and and print but its not happening can you please help thanks a ton