locked
CORS issue when connecting to Anomaly Detection API from a Notebook in Azure Machine Learning Studio RRS feed

  • Question

  • My code to connect to the Anomaly Detection web service is as shown below. I am receiving a CORS error while connecting to it from my notebook in ML studio. What should I do to get that fixed? Also my Machine Learning workspace is in west central and my python notebooks are getting created in https://europewest.notebooks.azureml.net. Is there a reason why? If they get created in west central I believe I will not run in to CORS error. Does Azure ML Studio create python notebooks in europewest byd default?

    def detectAnomalies(values):
        data = {
                "Inputs": {
                        "input1":
                        [
                            {
                            "ColumnNames": ["Time", "Data"],
                            "Values": values   
                            }
                        ],
                },
            "GlobalParameters":  {
                'detectors.historywindow': "1",
                'preprocess.aggregationInterval': "1",
                'preprocess.aggregationFunc': "mean",
                'preprocess.replaceMissing': "lkv",
                'seasonality.enable': "false",
                'seasonality.numSeasonality': "1",
                'seasonality.transform': "none",
                'postprocess.tailRows': "1",
                'negtrenddetector.sensitivity': "1",
                'bileveldetector.sensitivity': "1",
                'postrenddetector.sensitivity': "1",
                'zspikedetector.sensitivity': "1",
                'tspikedetector.sensitivity': "1",
                'detectors.spikesdips': "Both",
            }
        }

        body = str.encode(json.dumps(data))
      
        url = 'https://uswestcentral.services.azureml.net/subscriptions/f548b13fddcf4486ac9f058026bc4b8b/services/bda675b8fdc040fb92178e088e4d141e/execute?api-version=2.0&format=swagger'
        Anomaly_Detection_KEY = ''
        headers = {'Content-Type':'application/json', 'Authorization':('Bearer '+ Anomaly_Detection_KEY)}
        
        req = urllib.request.Request(url, body, headers)

        try:
            response = urllib.request.urlopen(req)

            result = response.read()
            print(result)
        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')))





    • Edited by Sashank406 Tuesday, September 18, 2018 4:04 PM
    Tuesday, September 18, 2018 3:50 PM

All replies