forked from udacity/nd0821-c3-starter-code
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi.py
50 lines (42 loc) · 1.16 KB
/
api.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
"""API Deployment for the Census application.
Author: Ollie Tian
Date: Nov 2022
Pylint score
"""
import ssl
try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
pass
else:
ssl._create_default_https_context = _create_unverified_https_context
import json
import requests
import warnings
warnings.filterwarnings("ignore")
# Declare predict uri and sample dictionary
PREDICT_URI = "https://deploy-ml-with-heroku-offtian.herokuapp.com/predict"
sample = {
"age": 39,
"workclass": "State-gov",
"fnlgt": 77516,
"education": "Bachelors",
"education-num": 13,
"marital-status": "Never-married",
"occupation": "Adm-clerical",
"relationship": "Not-in-family",
"race": "White",
"sex": "Male",
"capital-gain": 2174,
"capital-loss": 0,
"hours-per-week": 40,
"native-country": "United-States",
}
# Retrieve response using POST
response = requests.post(PREDICT_URI, data=json.dumps(sample), timeout=30, verify=False)
dictionary = {
"Request body": sample,
"Status code": response.status_code,
"Response body": response.json()["fetch"],
}
print(json.dumps(dictionary, indent=4))