Reputation: 1751
Simple WebHooks Receiver I'm following this tutorial on webhooks with kloudless. I downloaded ngrok and set a URL to point to a local server and then setup a server using Python -m SimpleHTTPServer 8080
. I ran POST requests with the URL ngrok gave me and was able to see/navigate my local directories. I want to use this script to verify the webhook sender and launch a task.
#!/usr/bin/env python
from flask import Flask, request, abort
import hmac
import base64
import hashlib
import threading
app = Flask('demo_app')
APP_ID = ''
API_KEY = ''
@app_route('/webook', methods=['POST']) //FIX. @app_route should be @app.route
def receiver():
# Verify the Request Signature
digest = hmac.new(API_KEY,msg=request.data,digestmod=hashlib.sha256).digest()
sig = base64.b64encode(digest)
if not sig == request.headers.get('X-Kloudless-Signature'):
abort(403)
# Since the request is verified we can actually do something
account_id = request.form.get('account')
if account_id:
threading.Thread(target=process_account, args=(account_id,)).start()
# In order to verify that the endpoint is alive you should always return your application id with a 200 OK response
return APP_ID
if __name__ == 'main':
app.run()
I'm getting an error
@app_route('/webhook ', methods=['POST'])
NameError: name 'app_route' is not defined
Do I specify the URL that ngrok set up using localhost for the @app_route
?
UPDATE
the @app_route
should be left as /webhook
the external URL should be the https://046f3f46.ngrok.io/webhook
as an example.
Now I'm trying to figure why after I added this external URL to my dev portal under current webhooks, it is giving me an unsupported POST
method when clearly the app supports it.
UPDATE
So the Python SimpleHTTPSever
does not support the POST method.
I have found that this python server does support the GET and POST methods(well it's supposed to), however I'm getting a 405 error code which again is an unsupported method. Not sure what's going on, it has to be something in the environment.
Upvotes: 0
Views: 279