QuestionQ467

Using APIs

A developer is building a Python Flask solution that uses the Cisco Meraki Location API. Drag the code snippets into the blanks in the Python script to handle incoming location data. Not every option is used.

Drag & Drop
flask
route
publish
app
run
or
and
from flask import Flask
from flask import request
app = Flask(__name__)

@.('/', methods=['POST'])
def get_cmxJSON():
    cmxdata = request.json
    if not cmxdata  not 'data' in cmxdata:
        return ("invalid data", 400)

    print("Received data from ", request.environ['REMOTE_ADDR'])
    print(cmxdata)
    return "Location Scanning Data Received"

if __name__ == '__main__':
    main(sys.argv[1:])
    app.(port=5000)
Explanation

Flask routes are declared with the @app.route(...) decorator. Incoming JSON is invalid if the request has no JSON body or the parsed JSON lacks the required data key, which requires or. The Flask application instance starts its server through app.run(port=5000).

Community Discussion

No comments yet. Be the first to start the discussion!