Problem description: I have a python app with Flask that hosts a tiny API for me. Today it just stopped working. Trying to access it give me the error page with the binoculars accusing replit to not working propertly and to try again in 30 seconds. If i try to check the app on my replit profile, it still stucked on the loading and never boot. Looks like a problem with replit…
Expected behavior: API online and reachable through the URL.
Actual behavior: Stuck on booting and never boots.
Steps to reproduce: Access the link https://sintegre-hook.alvarofsj.repl.co through browser.
Bug appears at this link: https://sintegre-hook.alvarofsj.repl.co
Browser/OS/Device: Vivaldi on Windows 10
This can be caused by an error in your Python code. I will look it over.
2 Likes
Could you send code so I can see the issue?
1 Like
Thanks Mr. Regular XD (wish I was such a good member of community
)
1 Like
Don’t know for sure but try:
#!/usr/bin/env python
#*- coding: utf-8 -*-
import os, waitress
import pandas as pd
from flask import Flask, request, jsonify, render_template
from flask_httpauth import HTTPTokenAuth
# Init app
app = Flask(__name__)
basedir = os.path.abspath(os.path.dirname(__file__))
## Auth -------------------------------------------------------
#auth = HTTPTokenAuth(scheme='Bearer')
#tokens = {
# 'ilebZSxO903EvOj4XcYrFrZR4hwzZmidfp8P5WUsy36TF8sGvBePhsLMKmKx6Dmu': 'ons'
#}
#
#
#@auth.verify_token
#def verify_token(token):
# if token in tokens:
# return tokens[token], 200
#
# else:
# return None, 400
##-------------------------------------------------------------
# Base html --------------------------------------------------
@app.route('/', methods=['GET'])
def index():
df_not = pd.read_csv("new_notif.csv",sep=";")
return render_template(
'table.html',
tables=[df_not.to_html(classes='table', table_id='notif', index=False),],
titles=['', 'Notificações']
)
#-------------------------------------------------------------
# Get data from server ---------------------------------------
@app.route("/get_data",methods=['GET'])
def get_data():
df_not = pd.read_csv("new_notif.csv",sep=";")
return jsonify(df_not.to_json(orient='records'))
#-------------------------------------------------------------
# Clear Notifications ----------------------------------------
@app.route('/clear_notification', methods=['GET'])
def clear_notif():
df_new = pd.DataFrame([float("NaN")],columns=['url'])
df_new.to_csv("new_notif.csv",sep=";",index=False,encoding='utf-8-sig')
return jsonify(df_new.to_json(orient='records'))
#-------------------------------------------------------------
# Post notification ------------------------------------------
@app.route('/new_notification', methods=['POST'])
#@auth.login_required()
def new_notif():
df_not = pd.read_csv("new_notif.csv",sep=";") # Le arquivo ja existente
df_new = pd.io.json.json_normalize(request.get_json(force=True)) # Le request do server do ONS
if df_not[df_not['url'].isnull()].empty: # Caso possua dados, concatena
df_new = pd.concat([df_not,df_new],ignore_index=True,sort=False)
df_new.to_csv("new_notif.csv",sep=";",index=False,encoding='utf-8-sig') # Senao, apenas salva o arquivo
print(request.data)
print('\n\n\n')
print(request.headers)
return jsonify(request.json)
#-------------------------------------------------------------
# Run Server -------------------------------------------------
if __name__ == '__main__':
app.debug = False
port = int(os.environ.get('PORT', 33507))
waitress.serve(app, host="0.0.0.0") # changed host to 0.0.0.0?
#-------------------------------------------------------------
2 Likes
It was working just fine yesterday and most of the days before that. Sometimes it went asleep, but i could wake it up just by accessing the weblink. Now looks just that it’s stuck at booting forever.
1 Like
Oh but you are. You are invaluable and I would be lost without your help. Many people would be.
2 Likes
Oh. Thank you so much. It means a lot to know someone really enjoyed my help, but obviously I don’t qualify XD
2 Likes
I can’t even see my code on the panel anymore. It keeps like “loading” the files panel but never loads.
Oh. That is odd. Um, how about try making another repl, it seems this one has been corrupted/you used up storage space
EDIT: reason is if I fork the repl I can run it just fine
2 Likes
I think it could be corrupted, because storage is basically the codes and a csv with 1kb or less. Look at this:
I changed the server code (the last part) and it works:
# Run Server -------------------------------------------------
# if __name__ == '__main__':
app.debug = False
#port = int(os.environ.get('PORT', 3z7))
#waitress.serve(app, port=port)
app.run(host="0.0.0.0",port=5000)
#-------------------------------------------------------------
1 Like
Yes they seem to not want logs as well as trying to make it a WSGI non development server, but those work. I also can run it just fine without any modifications by forking…
1 Like
Oh it does. There was just no console output. For some reason my webview is blank and I have to open it in a new tab to see anything. It seems like Flask doesn’t always update in webview right away.
1 Like
Yeah, just forked it and it went good. Looks like it’s corruped. I didn’t know that was possible.
1 Like
mmmm, yes making a non development webserver via deployment in waitress will cause all logs to cease
1 Like
Yeah sorry about that replit can be funky (if you want you can mark my answer as solved
)
EDIT: thanks 
2 Likes