import urllib.request import json data = { "Inputs": { "input1": [ { 'august': "4", } ], }, "GlobalParameters": { } } body = str.encode(json.dumps(data)) url = 'https://ussouthcentral.services.azureml.net/workspaces/66e373b2084d4ffa9395c0e34ce9ccaa/services/6a7377c4a0db4ee3a4c88c2f52930fb8/execute?api-version=2.0&format=swagger' api_key = 'e1Hj4uDUvJgOSajw+EUsV5Emx3P+d1wHWThq5pNzALRVIXrw+e/U9ZQ4TI4sFo0AOYo13AIR4PlM6csSfgJKQA==' # Replace this with the API key for the web service headers = {'Content-Type':'application/json', 'Authorization':('Bearer '+ api_key)} req = urllib.request.Request(url, body, headers) try: response = urllib.request.urlopen(req) result = response.read() print(result) obj=json.loads(result.decode("utf-8")) print(obj["Results"]["output1"][0]["R Output JSON"]) robj=json.loads(obj["Results"]["output1"][0]["R Output JSON"]) print(robj["sections"][2]["values"][0]["data"]) import base64 with open("imageToSave.png", "wb") as fh: fh.write(base64.decodebytes(bytes(robj["sections"][2]["values"][0]["data"], 'utf-8'))) except urllib.error.HTTPError as error: print("The request failed with status code: " + str(error.code)) # Print the headers - they include the requert ID and the timestamp, which are useful for debugging the failure print(error.info()) print(json.loads(error.read().decode("utf8", 'ignore')))