· 5 years ago · Feb 23, 2021, 07:34 PM
1import urllib.request
2import json
3import os
4import ssl
5
6def allowSelfSignedHttps(allowed):
7 # bypass the server certificate verification on client side
8 if allowed and not os.environ.get('PYTHONHTTPSVERIFY', '') and getattr(ssl, '_create_unverified_context', None):
9 ssl._create_default_https_context = ssl._create_unverified_context
10
11allowSelfSignedHttps(True) # this line is needed if you use self-signed certificate in your scoring service.
12
13data = {
14 "data":
15 [
16 {
17 'Gender': "example_value",
18 'Nationality': "example_value",
19 'Age': "0",
20 'Serum Creatinine': "0",
21 'Height': "0",
22 'Weight': "0",
23 'Systolic': "0",
24 'Diastolic': "0",
25 },
26 ],
27}
28
29body = str.encode(json.dumps(data))
30
31url = 'http://6c320161-ab85-4867-a96a-7f47cbbd2c21.southeastasia.azurecontainer.io/score'
32api_key = '' # Replace this with the API key for the web service
33headers = {'Content-Type':'application/json', 'Authorization':('Bearer '+ api_key)}
34
35req = urllib.request.Request(url, body, headers)
36
37try:
38 response = urllib.request.urlopen(req)
39
40 result = response.read()
41 print(result)
42except urllib.error.HTTPError as error:
43 print("The request failed with status code: " + str(error.code))
44
45 # Print the headers - they include the requert ID and the timestamp, which are useful for debugging the failure
46 print(error.info())
47 print(json.loads(error.read().decode("utf8", 'ignore')))