Fix reponse already sent error
This commit is contained in:
		| @@ -60,11 +60,11 @@ async def view_doorboy_uids(request): | |||||||
|  |  | ||||||
| @app.route("/longpoll", stream=True) | @app.route("/longpoll", stream=True) | ||||||
| async def view_longpoll(request): | async def view_longpoll(request): | ||||||
|     response = await request.respond(content_type="text/event-stream") |  | ||||||
|     key = request.headers.get("KEY") |     key = request.headers.get("KEY") | ||||||
|     if not key or key not in [DOORBOY_SECRET_FLOOR, DOORBOY_SECRET_WORKSHOP]: |     if not key or key not in [DOORBOY_SECRET_FLOOR, DOORBOY_SECRET_WORKSHOP]: | ||||||
|         return text("Invalid token") |         return text("Invalid token") | ||||||
|  |  | ||||||
|  |     response = await request.respond(content_type="text/event-stream") | ||||||
|     await response.send("data: response-generator-started\n\n") |     await response.send("data: response-generator-started\n\n") | ||||||
|     pipeline = [ |     pipeline = [ | ||||||
|         { |         { | ||||||
| @@ -80,7 +80,9 @@ async def view_longpoll(request): | |||||||
|                 if event["fullDocument"].get("type") == "open-door": |                 if event["fullDocument"].get("type") == "open-door": | ||||||
|                     await response.send("data: %s\n\n" % |                     await response.send("data: %s\n\n" % | ||||||
|                                         event["fullDocument"]["door"]) |                                         event["fullDocument"]["door"]) | ||||||
|     except pymongo.errors.PyMongoError: |     except pymongo.errors.PyMongoError as e: | ||||||
|  |         print(e) | ||||||
|  |         await response.send("data: response-generator-ended\n\n") | ||||||
|         return |         return | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user