-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_request.py
47 lines (43 loc) · 1.32 KB
/
test_request.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
import requests
import json
import time
def test_runtask_keyword():
url = "http://127.0.0.1:5000/runtask"
data = {
'type':'keyword',
'keywords':['add','sub']
}
res = requests.post(url,data=data)
print(res.content)
return json.loads(res.content.decode("utf-8"))
def test_get_report(html):
url = "http://127.0.0.1:5000/report/"+html
res = requests.get(url)
print(res.content)
def test_get_status(taskid):
url = "http://127.0.0.1:5000/getTaskStatus"
data = {
"taskid":taskid,
}
res = requests.post(url,data=data)
# print(res.content.decode("utf-8"))
# print(json.loads(res.content.decode("utf-8")))
jsonobj = json.loads(res.content.decode("utf-8"))
# print("raw type:",type(jsonobj))
if jsonobj is None:
jsonobj = {"status": "PENDING", "id": taskid}
return jsonobj
else:
print(res.content.decode("utf-8"))
print(json.loads(res.content.decode("utf-8")))
jsonobj = json.loads(json.loads(res.content.decode("utf-8")))
return jsonobj
if __name__=="__main__":
jsonobj = test_runtask_keyword()
taskid = jsonobj['id']
# test_get_report()
res = test_get_status(taskid)
while res['status'] == "PENDING":
time.sleep(1)
res = test_get_status(taskid)
print("type:",type(res))