@AnderZero

Загрузил маленький python сервер на Flask, использующий модуль с playwright, на heroku. При попытке обратиться выдаётся ошибка, что делать?

Итак, я пишу маленький сервер на Python. Использую модуль требующий playwright. Для того, чтобы загрузить сервер на heroku использую сборочный пакет heroku-playwright-buildpack(GitHub). При попытке обратиться к эндпоинтам получают ошибку - Cannot GET /authors/get. Возвращается код - 404.
Прикрепляю исходный код:
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)

Логи:
Логи

2021-06-23T11:06:28.043198+00:00 app[web.1]:
2021-06-23T11:06:28.043221+00:00 app[web.1]: > heroku-playwright-example@1.0.0 start /app
2021-06-23T11:06:28.043222+00:00 app[web.1]: > node src/index.js
2021-06-23T11:06:28.043222+00:00 app[web.1]:
2021-06-23T11:06:28.613096+00:00 app[web.1]: Listening on port 36254!
2021-06-23T11:06:29.121638+00:00 heroku[web.1]: State changed from starting to up
2021-06-23T11:06:31.857041+00:00 heroku[router]: at=info method=GET path="/" host=tiktoknotificator.herokuapp.com request_id=4c25ec3a-72c6-43ea-9210-078149073d0d fwd="195.178.21.59" dyno=web.1 connect=0ms service=15ms status=200 bytes=4469 protocol=https
2021-06-23T11:06:32.446866+00:00 app[web.1]: Incoming request for browser 'chromium' and URL 'https://github.com/microsoft/playwright'
2021-06-23T11:06:35.389364+00:00 heroku[router]: at=info method=GET path="/browser/chromium?url=https%3A%2F%2Fgithub.com%2Fmicrosoft%2Fplaywright" host=tiktoknotificator.herokuapp.com request_id=3252e90b-0ed7-4b91-bd12-c2cc4582426a fwd="195.178.21.59" dyno=web.1 connect=0ms service=2950ms status=200 bytes=319629 protocol=https
2021-06-23T11:06:39.032620+00:00 heroku[router]: at=info method=GET path="/authors/get" host=tiktoknotificator.herokuapp.com request_id=ef81753e-8a3f-46e8-81ce-9d77b1e29bad fwd="195.178.21.59" dyno=web.1 connect=1ms service=3ms status=404 bytes=394 protocol=https

Заранее спасибо.
  • Вопрос задан
  • 108 просмотров
Пригласить эксперта
Ответы на вопрос 1
deepblack
@deepblack
В коде который ты привёл, не обрабатывается путь
authors/get
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы