forked from vaaaaanquish/rust-machine-learning-api-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample_request.py
More file actions
23 lines (17 loc) · 703 Bytes
/
Copy pathsample_request.py
File metadata and controls
23 lines (17 loc) · 703 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import base64
import json
try:
import requests
except:
print("// -----------------------\n[requirement] pip install requests\n// --------------------------")
raise
def request_image(img):
print('request to localhost:3000')
res = requests.post('http://127.0.0.1:3000', data=json.dumps({'img': img}), headers={'content-type': 'application/json'})
print('response\n', json.dumps(json.loads(res.text), indent=2))
# get sample image
print('get sample image from rust-lang.org')
sample_image_response = requests.get('http://rust-lang.org/logos/rust-logo-128x128-blk.png')
img = base64.urlsafe_b64encode(sample_image_response.content).decode('utf-8')
# request
request_image(img)