Flask server setup for one REPL works, but the same code in a new REPL doesn't?

I’m making a flask server on a DiscordBot Repl, but for some reason after it loads the html page, down in the bottom right of console, I see the notification “Reconnecting” “Connected” pop up and that causes the Flask server to stop displaying the HTML page. I have the same code in an older DiscordBot Repl, but I don’t run into any issues displaying the html page and don’t get the “Reconnecting” “Connecting” notification.
Repl link/Link to where the bug appears:
Screenshots, links, or other helpful context:
Here’s the older REPL that has the same Flask server setup except it has more app routes and some database connections:
DiscordBot REPL working code:

from flask import Flask, render_template, request
from threading import Thread
import sqlite3
import sys

app = Flask(__name__)

con = sqlite3.connect('tinker.db')
print("Opened database successfully")

con.execute("""CREATE TABLE IF NOT EXISTS users (
 user TEXT,
 user_id INTEGER UNIQUE);""")
print("Table created successfully")

def home():
    return render_template('user.html')

@app.route('/webhook', methods = ['POST'])
def webhook():
   print("Recieved Webhook")
   if request.method == 'POST':
     return 'Success', 200

def new_user():
    return render_template('home.html')

def stats():
   return render_template('stats.html')

@app.route('/addrec', methods = ['POST','GET'])
def addrec():
     if request.method == 'POST':
         dn = request.form['dn']
         di = request.form['di']

         with sqlite3.connect("tinker.db") as con:
             cur = con.cursor()
             cur.execute("INSERT INTO users (user, user_id) VALUES (?,?)",(dn, di) )
             msg = "Record successfully added"
          msg = "error in insert operation"
         if di == '425477636333240331':
           return render_template("result.html", msg = msg)
         if ((not dn) or (not di)):
           msg = "Please fill the required fields"

           return render_template("user.html", msg = msg)

           return render_template("thx.html", msg = msg)
       return render_template("user.html")

def list():
    con = sqlite3.connect("tinker.db")
    con.row_factory = sqlite3.Row
    cur = con.cursor()
    cur.execute("select * from users")
    rows = cur.fetchall(); 
    return render_template("list.html",rows = rows)

def help_list():
    return render_template('documentation/docs.html')
    print("Page under ")

def rps():
    return render_template('documentation/rps.html')

def support():
    return render_template('documentation/support.html')

def donate():
    return render_template('documentation/donate.html')

def don():
    return render_template('documentation/don.html')

def work():
    return render_template('documentation/work.html')

def vote():
    return render_template('documentation/vote.html')

def youtube():
    return render_template('documentation/youtube.html')

if __name__ == "__main__":

def run():

def keep_alive():
     t = Thread(target=run)

Nopenheimer REPL not working code:

from flask import Flask, render_template
from threading import Thread

app = Flask(__name__)

def home():
  return render_template('home.html')

if __name__ == "__main__":

def run():

def keep_alive():
  t = Thread(target=run)

Ofc, it’s entirely possible the error is somewhere else, but… I genuinely don’t know what’s causing this behavior and I’m wondering if it may be an environment issue
where something is different that I can’t see.

Hey @LyndenSylver!

Try changing:


if __name__ == "__main__":
1 Like

I suspect the weird replit.dev URL is the culprit, but I have no way to check that myself.

As that’s the one major difference between the old Repl and Newer REPLs, my old one used the old URL format, but the new one uses the replit.dev format

I tried that, but it made no difference. I’m wondering if it’s some weird bug that only exists in newer repls (post- AlwaysOn Removal, and change to deployments and replit.dev URLS)

Because it seems my repl that existed before those changes works perfectly fine, but even forking my code from that old REPL to a new one, doesn’t work with exactly identical code.

I’m sorry, I should have read your original post more. A disconnect-reconnect loop shouldn’t actually be tied to the Repl itself, could you share network logs of the tab that has your Repl open? I’m suspecting some critical domain is getting blocked, causing the issue.


I have the .har file, but it’s not among the supported formats for uploading, but here’s screenshots of the network log:

Does the Console have any errors?
Also, try visiting replit.dev. Can you see the Replit page about not running, or is it blocked by any firewalls/ISPs?

Just took a look at the .har file using Google Admin Toolbox Har Analyzer, and it looks like the style.css file throws a 502 error, and then the replit.dev URL also throws 2 502 errors.

Here’s the style.css:

body {
  background-color: #73d2a0;
  color: #000000;

.btn {
  display: inline;
  padding: 15px 25px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  background-color: #d30f0f;
  color: #ffffff;
  outline: none;

  border: none;
  border-radius: 15px;
  box-shadow: 0 9px #999;

.btn:hover {background-color: #757575}

.btn:active {
  background-color: #360000;
  box-shadow: 0 5px #007e30;
  transform: translateY(4px);

.required { 
  color: #690000; 

small {
  font-size: 16px;

The console throws no errors, and the webview has the ASCII computer, keyboard, and mouse and below it it says “Looks like you have a server running.” and the blue button saying “Show web content”. Clicking that button gets me the “Hmm… We couldn’t reach this Repl” “Make sure this Repl has a port open and is ready to receive HTTP traffic” page in the webview. I do have an open port on :8080. I don’t think anything is blocked by firewalls or ISPs

Does changing it to this work?

<link rel="stylesheet" href="/static/css/style.css ">

Then, in your keep_alive.py, try changing it to:

from flask import Flask, render_template
from threading import Thread

app = Flask(__name__)

def home():
  return render_template('home.html')

def run():
def keep_alive():
  t = Thread(target=run)

if __name__ == "__main__":

I removed the app.run in the if statement, calling it later.
Try this, see if it works.

yes and no? It sorta works but resets to a blank white page after a couple seconds and then goes to the “Looks like you have a server running” page. It also doesn’t fix the reconnect-connect issue. With your tweaks it sometimes uses the stylesheet for the html, and other times doesn’t before setting to the white page

1 Like

I wonder… Could you try opening it in a new tab in the short time before it disconnects, and then don’t use the Webview tab, does the issue still occur?

It’s such a small window of time between when it loads up and when it starts the reconnect-connect loop (a matter of miliseconds) that the reconnect-connect loop starts when I open it in a new tab (which lands me on the “Hmm… We couldn’t reach this Repl” page)