Python flask server won't receive anything when called from ifttt webhook

1.2k views Asked by At

So i am pretty new to Python Web servers and was following this question

How to setup a Raspberry Pi to receive webhooks

to receive a webhook from Ifttt in order to control my TV and AC but my server does't show any message from the Ifttt server. I have checked that my server is visible from the internet and i can trigger it using a proxy.

Python Code:

from flask import Flask
import subprocess

app = Flask(__name__)

tv_Power = "irsend SEND_ONCE TV KEY_POWER"
AC_On = "irsend SEND_ONCE AC on on on on on on"
AC_Off = "irsend SEND_ONCE AC off off off off off off off off off off off off off"

@app.route('/', methods = ['POST'])
def index():
    return 'Choose Option'

@app.route('/tv_Power',methods=['POST'])
def pow():
    process = subprocess.Popen(tv_Power.split(), stdout=subprocess.PIPE)
    output, error = process.communicate()
    return 'Changing TV State'

@app.route('/AC_On',methods=['POST'])
def acon():
    process = subprocess.Popen(AC_On.split(), stdout=subprocess.PIPE)
    output, error = process.communicate()
    return 'Turning AC On'

@app.route('/AC_Off',methods=['POST'])
def acoff():
    process = subprocess.Popen(AC_Off.split(), stdout=subprocess.PIPE)
    output, error = process.communicate()
    return 'Turning AC Off'

if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0')

Ifttt webhook settings:

enter image description here

2

There are 2 answers

5
Stanton On

All of your routes are defined to be POST. Perhaps

methods=['POST','GET']
1
Artem B On

Here are some fixes:

  1. All of the routes in the code are POST endpoints, weather IFTTT webhook is posting GET request (editable under Method field);
  2. Make sure also that the port on which the flask server is running is open and requests from IFTTT not blocked by the router (if you use one).

Check out my article: IFTTT, Python, and Flask