import urllib.request import json data = { "Inputs": { "input1": [ { 'arv': "1", } ], }, "GlobalParameters": { } } body = str.encode(json.dumps(data)) url = 'https://ussouthcentral.services.azureml.net/workspaces/66e373b2084d4ffa9395c0e34ce9ccaa/services/3718b7a59159465bae6f2e296c5ac1b9/execute?api-version=2.0&format=swagger' api_key = 'hst6iEhiprvnQ3RWaL5j1uWFuxCgDHd0cJPznmShuQ3x91UpFYmSV+b5c74iG1M3hDruoAw2KKwjP89QRlhuxg==' # 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) print(obj) 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')))