-
Notifications
You must be signed in to change notification settings - Fork 0
/
postman_req.py
53 lines (49 loc) · 1.5 KB
/
postman_req.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
51
52
53
#!/usr/bin/env python
import requests
import os
# set spark as kind
url = "http://localhost:8998/sessions"
payload = "{\"kind\":\"spark\"}"
headers = {
'content-type': "application/json",
'cache-control': "no-cache"
}
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text, response.headers, url)
location = response.headers['Location']
# list all sessions
url = "http://localhost:8998/sessions"
headers = {
'content-type': "application/json",
'cache-control': "no-cache"
}
response = requests.request("GET", url, headers=headers)
print(response.text, response.headers, url)
#send statement to process
url = "http://localhost:8998" + location + "/statements"
payload = "{\"code\":\"print(\\\"asd\\\")\"}"
headers = {
'content-type': "application/json",
'cache-control': "no-cache"
}
statement_location = None
while True:
response = requests.request("POST", url, data=payload, headers=headers)
if response.status_code == 201:
print(response.text, response.headers, url)
statement_location = response.headers['Location']
os.system('sleep 5')
break
else:
os.system('sleep 0.5')
# get results of a task
if statement_location is not None:
url = "http://localhost:8998" + statement_location
headers = {
'content-type': "application/json",
'cache-control': "no-cache"
}
response = requests.request("GET", url, headers=headers)
print(response.text)
else:
print 'Error'