Skip to content

Commit 6c1af54

Browse files
committed
Use raw POST
1 parent 5d6fd95 commit 6c1af54

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ With `python github_adapter.py` you will check for new issues and a POST request
2626

2727
You can also use only `python siren.py [port]` and make a POST:
2828

29-
`http -f POST http://localhost:8080/light actor=my_test duration=3`
29+
`http POST http://localhost:8080/light actor=my_test duration=3`
3030

3131
I manage it with [supervisord](http://supervisord.org/) on Raspbian.
3232

github_adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def check_and_send_light_request(urgent_ticket):
2020
# request to beacon light
2121
logging.info('New urgent ticket found: {}'.format(urgent_ticket))
2222
payload = {'actor': 'github_adapter', 'duration': LIGHT_SECONDS}
23-
requests.post(BASE_URL + '/light', data=payload)
23+
requests.post(BASE_URL + '/light', json=payload)
2424

2525

2626
if __name__ == '__main__':

siren.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3+
import json
34
import logging
45
import sys
56
import time
@@ -21,8 +22,10 @@
2122

2223
class light:
2324
def POST(self):
24-
i = web.input()
25-
turn_on_the_light(i.duration, i.actor)
25+
data = json.loads(web.data() or '{}')
26+
if not 'duration' in data or not 'actor' in data:
27+
return web.badrequest()
28+
turn_on_the_light(data['duration'] or 1, data['actor'])
2629
return web.nocontent()
2730

2831

0 commit comments

Comments
 (0)