I'm trying to check for registration, and when it comes to the for loop in the function it stops and gives me the error: pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 61] Connection refused, Timeout: 30s, Topology Description: <TopologyDescription id: 631775bf7b8ce9e8bde619fa, topology_type: Unknown, servers: [<ServerDescription ('localhost', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('localhost:27017: [Errno 61] Connection refused')>]>
my app.py :
app = Flask(__name__,static_url_path='',static_folder="static")
app.secret_key = 'just a string'
app.config["MONGO_URI"] = "mongodb+srv://Beny1320001:Beny132001@cluster0.dn45iia.mongodb.net/?retryWrites=true&w=majority"
myclient = pymongo.MongoClient('mongodb://localhost:27017/')
user_db = myclient["authentication"]
user_table = user_db["user_info"]
@app.route("/register_check", methods=['GET', 'POST'])
def register_check():
if request.method == 'POST':
req = request.form
req = dict(req)
query = user_table.find({'uid':req['uid']})
virable = 0
for x in query:
if x['uid'] == req['uid']:
virable = 1
break
req_dict = {'uid':req['uid'],'email':req['email'],'password':req['password']}
if virable == 0:
user_table.insert_one(req_dict)
return render_template('dashboard.html', uid = req['uid'])
else:
return render_template('invalid.html', message = 'User alaredy exists')
return render_template('register.html')