forked from hkust-itsc/itsc_facial_reg_server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_facial_reg.py
38 lines (31 loc) · 1.12 KB
/
test_facial_reg.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
import base64
import json
from urllib.request import Request, urlopen
import requests
SERVER = "192.168.0.188:18080"
def ws_client(url, method=None, data=None, files=None):
if not method:
method = "POST" if data else "GET"
if data:
data = json.dumps(data).encode("utf-8")
headers = {"Content-type": "multipart/form-data; charset=UTF-8"} \
if data else {}
req = Request(url=url, data=data, headers=headers, method=method)
with urlopen(req) as resp:
result = json.loads(resp.read().decode("utf-8"))
return result
if __name__ == "__main__":
im1 = None
im2 = None
with open('face1.jpg', "rb") as f:
im_bytes = f.read()
im_1 = base64.b64encode(im_bytes).decode("utf8")
with open('face2.jpg', "rb") as f:
im_bytes = f.read()
im_2 = base64.b64encode(im_bytes).decode("utf8")
files = [('face_images', im_1), ('face_images', im_2)]
data = {'eppn': 'example.connect.ust.hk'}
res=requests.post(f"http://{SERVER}/register",files=files, data=data)
print(res.status_code)
print(res.headers)
print(res.content.decode("ascii"))