从ifttt webhook

时间:2017-08-28 16:56:14

标签: python flask webhooks ifttt

所以我对Python Web服务器很陌生并且正在关注这个问题

How to setup a Raspberry Pi to receive webhooks

Ifttt接收webhook以控制我的电视和AC,但我的服务器不会显示来自Ifttt服务器的任何消息。我已经检查过我的服务器是否可以从互联网上看到,我可以使用代理触发它。

Python代码:

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设置:

enter image description here

2 个答案:

答案 0 :(得分:0)

您的所有路线都定义为POST。也许

methods=['POST','GET']

答案 1 :(得分:0)

以下是一些修复程序:

  1. 代码中的所有路由均为POST端点,天气IFTTT webhook正在发布GET请求(可在“方法”字段下编辑);
  2. 还要确保正在运行烧瓶服务器的端口已打开,并且来自IFTTT的请求没有被路由器阻止(如果使用的话)。

查看我的文章: IFTTT, Python, and Flask