-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaml_endpoint_test.py
57 lines (48 loc) · 1.81 KB
/
aml_endpoint_test.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
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.
# Request data goes here
data = {
"Inputs": {
"data":
[
{
"Hydrogen": 2845,
"Oxigen": 5860,
"Nitrogen": 27842,
"Methane": 7406,
"CO": 32,
"CO2": 1344,
"Ethylene": 16684,
"Ethane": 5467,
"Acethylene": 7,
"DBDS": 19,
"Power factor": 1,
"Interfacial V": 45,
"Dielectric rigidity": 55,
"Water content": 0
},
]
},
"GlobalParameters": 1.0
}
body = str.encode(json.dumps(data))
url = 'http://PLEASE-ENTER-YOUR-OWNED-AML-ACI-ENDPOINT-NAME.southeastasia.azurecontainer.io/score'
api_key = 'PLEASE-ENTER-YOUR-OWN-API-KEY' # 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')))