I’m trying to build a webhook in Python to answer Dialogflow webhook. The code seems to be correct but generates a HTTP 405 . I checked several sites and the code should work. I really do not understand where the problem is coming from.
Any idea ?
thank you in advance.
from flask import Flask, request
app = Flask(__name__)
@app.route('/') # this is the home page route
def hello_world(): # this is the home page function that generates the page code
return "Hello world!"
@app.route('/webhook', methods=['POST'])
def webhook():
req = request.get_json(silent=True, force=True)
sum = 0
query_result = req.get('queryResult')
num1 = int(query_result.get('parameters').get('number'))
num2 = int(query_result.get('parameters').get('number1'))
sum = str(num1 + num2)
print('here num1 = {0}'.format(num1))
print('here num2 = {0}'.format(num2))
return {
"fulfillmentText": 'The sum of the two numbers is: '+sum,
"source": "webhookdata"
}
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080) # This line is required to run Flask on repl.it
No this a sample just to collect 2 numbers from dialogflow and then sent them to the webhook to be summed as a test. but nothing happen as I get a 405…
According to what I saw, you were creating an API to add two numbers, and a 405 error in flask means you were using the incorrect request method, as @dragonhunter1 stated.
Can you show me your server logs, like It will say GET at ROUTE. Just copy some of the console output. That should help us determine the invalid request type.
Hi Functionally. this is working now . I don’t know why but the change in the method is working. I did not restart my webhook properly.
Thank you very much !
Requests will not work unless you use the correct method because it is similar to a regular webpage. So I’m just as perplexed as you are because both me and @dragonhunter1 gave you advice to resolve your issue and it took so long.