Complete the code to import the Flask class.
from flask import [1]
The Flask class is imported from the flask module to create the app.
Complete the code to define a route that returns a JSON response.
@app.route('/status') def status(): return [1]({'status': 'ok'})
The jsonify function converts a Python dictionary to a JSON response.
Fix the error in the polling loop to wait 2 seconds between requests.
import requests import time while True: response = requests.get('/status') if response.json().get('status') == 'ok': break time.[1](2)
The time.sleep(seconds) function pauses the program for the given seconds.
Fill both blanks to create a polling endpoint that returns JSON with a message.
from flask import Flask, [1] app = Flask(__name__) @app.route('/poll') def poll(): return [2]({'message': 'Polling response'})
jsonify is imported and used to return JSON responses in Flask.
Fill all three blanks to create a polling loop that stops when server returns 'done'.
import requests import time while True: response = requests.get('[1]') if response.json().get('[2]') == '[3]': break time.sleep(1)
The polling URL is '/status', checking the 'status' key for the value 'done' to stop.
