Answer the question
In order to leave comments, you need to log in
Uploaded a small Flask python server using the playwright module on heroku. I get an error when I try to contact, what should I do?
So, I am writing a small server in Python. I'm using a module that requires playwright. In order to upload the server to heroku I use the heroku-playwright-buildpack ( GitHub ) build package. When trying to access endpoints, they get an error - Cannot GET /authors/get. The code returned is 404. I am
attaching the source code:
from gevent import monkey
monkey.patch_all()
from flask import Flask, Response
from TikTokApi import TikTokApi
from flask import request
import asyncio
import nest_asyncio
import json
nest_asyncio.apply()
tiktokapi = TikTokApi.get_instance()
global authorsL
authorsL = {}
app = Flask(__name__)
def str2bool(v):
return v.lower() in ("yes", "true", "t", "1")
authvideos = {}
@app.route('/videos/check')
def check():
return json.dumps(checkVideos())
@app.route('/authors/add', methods=['GET', 'POST'])
def add():
try:
global authorsL
if(request.args.get('name') is None or request.args.get('tiktok') is None):
return Response("Bad Request", status=400, mimetype='application/json')
if(request.args.get('name') in authorsL):
return Response("Bad Request", status=400, mimetype='application/json')
authorsL[request.args.get('name')] = {'tiktok': request.args.get('tiktok'), 'tiktokNotifications': True}
print(authorsL)
return Response("success", status=200, mimetype='application/json')
except Exception:
return Response("Server Error", status=500, mimetype='application/json')
@app.route('/authors/remove', methods=['GET', 'POST'])
def remove():
try:
global authorsL
if(request.args.get('name') is None):
return Response("Bad Request", status=400, mimetype='application/json')
if(request.args.get('name') not in authorsL):
return Response("Bad Request", status=400, mimetype='application/json')
authorsL.pop(request.args.get('name'))
print(authorsL)
return Response("success", status=200, mimetype='application/json')
except Exception:
return Response("Server Error", status=500, mimetype='application/json')
@app.route('/authors/get', methods=['GET'])
def get():
global authorsL
return json.dumps(authorsL)
@app.route('/authors/changeTiktok')
def changeTiktok():
try:
if(request.args.get('name') is None or request.args.get('tiktok') is None):
return Response("Bad Request", status=400, mimetype='application/json')
global authorsL
if(request.args.get('name') not in authorsL):
return Response("Bad Request", status=400, mimetype='application/json')
authorsL[request.args.get('name')]['tiktok'] = request.args.get('tiktok')
print(authorsL)
return Response("success", status=200, mimetype='application/json')
except Exception:
return Response("Server Error", status=500, mimetype='application/json')
@app.route('/authors/setTiktok', methods=['GET', 'PUT'])
def setTiktok():
try:
global authorsL
name = request.args.get('name')
if(name is None or request.args.get('notifications') is None):
return Response("Bad Request", status=400, mimetype='application/json')
if(name not in authorsL):
return Response("Bad Request", status=400, mimetype='application/json')
st = str2bool(request.args.get('notifications'))
authorsL[name]['tiktokNotifications'] = st
return Response("success", status=200, mimetype='application/json')
except Exception:
return Response("Server Error", status=500, mimetype='application/json')
@app.route('/authors/clear')
def clear():
global authorsL
authorsL = {}
return Response('success', status=200, mimetype='application/json')
if __name__ == '__main__':
checkVideos()
app.run(debug=True)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question