Uncategorized

Python flask app running on Pythonanywhere not able to send whatsapp messages through ngrok and twilio : Forums : PythonAnywhere


Hi,
I am new to all this. I created a SSH key and pulled my repo from Github.
So it created a directory “cbot”. I have a “venv” virtual environment.
Previously I was able to start the local server at port 5000
Then from another console I was runnung a ngrok tunnel at 5000 and I was pasting the Forwarding Link “https://c664-54-226-131-176.ngrok-free.app” to Twilio sandbox. But the code is not not able to send back messages. When i type a HI from my whatsapp, the ngrok tunnel shows that a twilio post was made but has no response.
This process works seamlessly in VSCode.
Now of sudden I am not able start the app as it says port 5000 is used by another program.

On using : ss -nltp
I find: LISTEN       0             128                                        127.0.0.1:5000                     0.0.0.0:*

However I am not able to kill the process.
I badly need your help to deploy this working app on pythonanywhere. If you want you can take access of my account and check what I am doing wrong. Thanks in advance.
The flask code is as follows

from flask import Flask, request
from document_gpt.helper.conversation import create_conversation
from document_gpt.helper.twilio_api import send_message
qa = create_conversation()
app = Flask(__name__)

@app.route('/', methods=['GET', 'POST'])
def home():
    return 'MAN', 200

@app.route('/twilio', methods=['POST'])
def twilio():
    query = request.form['Body']
    sender_id = request.form['From']
    print(sender_id, query)

    res = qa(
        {
        'question': query,
        'chat_history': {}
        }
    )

    print(res)

    send_message(sender_id, res['answer'])

    return 'MAN', 200

This is the run.py

from document_gpt.src.main import app

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



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *