예제 #1
0
def get_www_authenticate_header(api_url):
    try:
        resp = urllib.request.urlopen(api_url)
        response = resp.read()
    except urllib.error.HTTPError as error:
        response = error.info()['Www-Authenticate']
    return response
예제 #2
0
def apicall():
    id = "asus-geforce-gtx750ti-oc-2gd5-performance-graphics-gddr5-2gb"
    chk = []
    data = {
        "Inputs": {
            "input1": {
                "ColumnNames": ["month", "price", "item"],
                "Values": []
            },
        },
        "GlobalParameters": {}
    }
    for i in range(1, 13):
        data["Inputs"]["input1"]["Values"].append([str(i), "0", id])

    body = str.encode(json.dumps(data))

    url = 'https://ussouthcentral.services.azureml.net/workspaces/24af1e57b2794253957d65b08d00a725/services/dca5e0834086488e986f1efd0375ae2f/execute?api-version=2.0&details=true'
    api_key = 'IQW3L6TA21jChGgRgm8Z2w8xGeYtpUISi3b7fXY+/DKw1O7Mxrklwd3PKxUTHBuu43HybpCOtLfN+AuPOkYmbw=='  # 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().decode("utf-8")
        chk.append(json.JSONDecoder().decode(result))
    except (urllib.error.HTTPError):
        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()))

    ref = chk[0]["Results"]["output1"]["value"]["Values"]
    minN = ref[0][3]
    res = ref[0][0]
    for i in range(1, len(ref)):
        if (ref[i][3] < minN):
            res = ref[i][0]

    return render_template('index.html', result=calendar.month_name[int(res)])
예제 #3
0
def get_hate_score(text):
    data =  {
        "Inputs": {
            "input1":
                {
                    "ColumnNames": ["id", "label", "tweet"],
                    "Values": [ [ "0", "0", text],]
                    },        },
                "GlobalParameters": {}
    }

    body = str.encode(json.dumps(data))

    url = 'https://ussouthcentral.services.azureml.net/workspaces/75e2e65c01754c3f8d498e08a7c73e3b/services/48ce6baf8ee64b1e9ce0ab44d1a66da4/execute?api-version=2.0&details=true'
    api_key = 'PWLiMLplJTtcrX3S7v6X6kXNLB1uUSOhNHTHMfdMivroAl/S8y95n+tdD1w7EFjMRwqJxVxi8VJPFEC/W6Q3kQ=='
    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()
        result_str = str(result)
        result_str = result_str[result_str.index("Values"):]
        result_str = result_str[15:-8]

        if result_str.count("-") > 0:
            return 0
        else: 
            return float(result_str)
    
    except urllib.error.HTTPError as error:
        return 0
        print("The request failed with status code: " + str(error.code))
        print(error.info())
        print(json.loads(error.read())) 
예제 #4
0
def go(date):
    data = {
        "Inputs": {
            "input1":
            [
                {
                    'Date': date,
                }
            ],
        },
        "GlobalParameters":  {}
    }

    body = str.encode(json.dumps(data))

    # Replace this with the URI and API Key for your web service
    url = 'https://ussouthcentral.services.azureml.net/subscriptions/b0707550dad348bf9bbedd4529b65e0f/services/a79ba95060bc4daf9e38871c2827928a/execute?api-version=2.0&format=swagger'
    api_key = '+Em94oRHVYYnoZqzd51CqAxxKPC2lFG58IdhV81jlNJtkz7csCgzF4p5VlIEpWd3HF1L+UAYpzMIOQWJg9b09w=='
    headers = {'Content-Type':'application/json', 'Authorization':('Bearer '+ api_key)}

    # "urllib.request.Request(url, body, headers)" for Python 3.X
    req = urllib.request.Request(url, body, headers)
    print('DEBUG1')
    try:
        response = urllib.request.urlopen(req)
        result = response.read()
        print(result)
    # "urllib.error.HTTPError as error" for Python 3.X
    except urllib.error.HTTPError as error:
        print("The request failed with status code: " + str(error.code))
        # Print the headers - they include the request ID and the timestamp, which are useful for debugging the failure
        print(error.info())
        print(json.loads(error.read()))
    #
    result_str = result.decode()
    return ast.literal_eval(result_str)
예제 #5
0
                                    "other_installments", "housing_status", "num_credits", "job_type", 
                                    "num_dependant", "own_telephone", "foreign_worker", "credit_risk"],
                    "Values": [ [ "A12","48","A32","A43","5951","A61","A73","2","A92","A101","2",
                                 "A121","22","A143","A152","1","A173","1","A191","A201","2"],
                              [ "A12","48","A32","A43","5951","A61","A73","2","A92","A101","2",
                                 "A121","22","A143","A152","1","A173","1","A191","A201","2"]]
                },        },
            "GlobalParameters": {}
    }

body = str.encode(json.dumps(data))

url = 'YOUR OWN API URL'
# Replace this with the API key for the web service
api_key = 'YOUR_OWN_API_KEY' 
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) 
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()))