1

I am trying to pass a JSON request to Flask and deploy it in Azure function app. I followed this thread to deploy my Python Flask App on to Azure.I tested the code with GET request by passing parameters in the URL and it was working.

My requirement is to trigger the code by passing a JSON POST request. But when I test it, I get a "500 Internal Server Error" which says "The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application"

import logging
import azure.functions as func
import request
from flask import Flask, request, make_response, jsonify

app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello World!'

# function for responses (POST Request)
def results():
    # build a request object
    req = request.get_json(silent=True, force=True)

    # fetch action from json
    action = req.get('queryResult').get('action')

    # return a fulfillment response
    return {'fulfillmentText': 'This is a response from webhook.'}

# create a route for webhook
@app.route('/webhook', methods=['GET', 'POST'])
def webhook():
    # return response
    return make_response(jsonify(results()))

def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')
    uri=req.params['uri']
    with app.test_client() as c:
        doAction = {
            "GET": c.get(uri).data,
            "POST": c.post(uri).data
        }
        resp = doAction.get(req.method).decode()
        return func.HttpResponse(resp, mimetype='text/html')

My requirement.txt file looks like this.

enter image description here

S.Jo
  • 58
  • 5

0 Answers0