I am facing an error in flask Timeout error every time I rum my code this message comes:

109 Views Asked by At

TimeoutError TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

and here is my Python-flask code:

from flask import Flask, render_template , request
from flask_sqlalchemy import SQLAlchemy
from flask_mail import Mail, Message
import json

local_server = True
#json
with open("config.json", "r") as f:   #config.json ik main file hai jis k andar hamary different parameters hain
    params = json.load(f)["params"]




app = Flask(__name__,template_folder="./Template")

if(local_server==True):
    app.config["SQLALCHEMY_DATABASE_URI"] = params["local-uri"]    #ye local-uri json wali file se aa rha hai iss py jo link lagta hia wo us file ma mily ga
else:
    app.config["SQLALCHEMY_DATABASE_URI"] = params["product-uri"]  #same here 

#flask mail


app.config['MAIL_SERVER'] = "smtp.gmail.com"
app.config['MAIL_PORT'] = 443
app.config['MAIL_USE_SSL'] = True
app.config["MAIL_user"] = params["gmail-user"]
app.config["MAIL_PASSWORD"] = params["gmail-password"]

mail = Mail(app)

#from flask-alchemy


db = SQLAlchemy()      # ye du lines flask sqlalchemy se aa rahe hain
db.init_app(app)




# flask alchemy
class Contact(db.Model):                    #ye sara kuch database ma data dalny k liyay hai 
    Id = db.Column(db.Integer, primary_key=True, nullable=False)
    user_name = db.Column(db.String, unique=False, nullable=False)
    phone_number = db.Column(db.String, unique=True, nullable=False)
    email = db.Column(db.String, nullable=False)
    message = db.Column(db.String, nullable=False)

#flask module

@app.route("/")
def Home():
    return render_template('index.html')

@app.route("/about")
def About():
    return render_template('about.html')

@app.route("/contact", methods = ['POST', 'GET'])
def contact():
    if (request.method == 'POST'):
        # add entry to the data base 
        name = request.form.get('name')
        email = request.form.get('email')
        phone = request.form.get('phone')
        message = request.form.get("message")
        
        entry = Contact(user_name=name, phone_number = phone,email= email, message=message)
        db.session.add(entry)
        db.session.commit()         # always write this after commit

        msg = Message("New message from website",
                sender=email,
                recipients=[params["gmail-user"]])
        
        msg.body = message + "/n" + phone + "/n" + name
        mail.send(msg)

    return render_template('contact.html')

app.run(debug=True)

`

I need this to run because this is my first flask project.......

0

There are 0 best solutions below