A
A
AnderZero2021-06-22 15:43:49
Flask
AnderZero, 2021-06-22 15:43:49

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)

Logs:
Logs

2021-06-23T11:06:28.043198+00:00 app[web.1]:
2021-06-23T11:06:28.043221+00:00 app[web.1]: > [email protected] 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

Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2021-06-23
@deepblack

In the code you provided, the path is not processed
authors/get

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question