-
Notifications
You must be signed in to change notification settings - Fork 0
/
endpoint.py
80 lines (71 loc) · 2.6 KB
/
endpoint.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import urllib.request
import json
import os
import ssl
def allowSelfSignedHttps(allowed):
# bypass the server certificate verification on client side
if allowed and not os.environ.get('PYTHONHTTPSVERIFY', '') and getattr(ssl, '_create_unverified_context', None):
ssl._create_default_https_context = ssl._create_unverified_context
allowSelfSignedHttps(True) # this line is needed if you use self-signed certificate in your scoring service.
data = {"data":
[
{
"age": 17,
"campaign": 1,
"cons.conf.idx": -46.2,
"cons.price.idx": 92.893,
"contact": "cellular",
"day_of_week": "mon",
"default": "no",
"duration": 971,
"education": "university.degree",
"emp.var.rate": -1.8,
"euribor3m": 1.299,
"housing": "yes",
"job": "blue-collar",
"loan": "yes",
"marital": "married",
"month": "may",
"nr.employed": 5099.1,
"pdays": 999,
"poutcome": "failure",
"previous": 1
},
{
"age": 87,
"campaign": 1,
"cons.conf.idx": -46.2,
"cons.price.idx": 92.893,
"contact": "cellular",
"day_of_week": "mon",
"default": "no",
"duration": 471,
"education": "university.degree",
"emp.var.rate": -1.8,
"euribor3m": 1.299,
"housing": "yes",
"job": "blue-collar",
"loan": "yes",
"marital": "married",
"month": "may",
"nr.employed": 5099.1,
"pdays": 999,
"poutcome": "failure",
"previous": 1
},
]
}
body = str.encode(json.dumps(data))
url = 'http://0e7f21ea-cf46-4e26-9e6a-eece65cbfff3.uksouth.azurecontainer.io/score'
api_key = 'XOtuoeogOeYyCn1KHR3A1QmunHI39UHX' # 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)
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')))