Python Flask {GET POST} requests Webhook how to listen to a public address URL

Viewed 1378

Here is my requirements.

There is a webhook connected with certain public address .

> 52.89.214.238
> 34.212.75.30
> 54.218.53.128
> 52.32.178.7

This webhook will be used to post data either in json or text format. (Public webhook info is here https://www.tradingview.com/chart/?solution=43000529348)

Let say i wish to listen to this end point to parse the data further how to do this in python.

from flask import Flask, request, Response, jsonify

url ='https://52.89.214.238:443/callback/'  #this is the URL i wish to listen the POST message using Webhook
# POST request for webhook services.
@app.route('/callback', methods=['POST'])
def callback():
    temp = []
    dictList = []
    data = request.get_json(force=True)

if __name__ == "__main__":
    try:
        app.run(host=url, port=443, debug=False)
    except:
        print('Error occured, starting again...')
        pass

What changes i need to make here to listen to this public address and to parse the data.

1 Answers

Just change the host like below.

if __name__ == "__main__":
    app.run(host='52.89.214.238', port=443)

Since your are trying to access it over the internet, I would recommend using SSL certificate and validation token.

Related