K
K
khudobinvasiliy2021-04-02 20:04:00
PHP
khudobinvasiliy, 2021-04-02 20:04:00

How to resolve 500 error on Flask Heroku?

Good day. I've searched all over Google but haven't been able to find an answer. When uploading a site to heroku, I get an internal server error, although everything works on the local server. Here is main.py:

# импортирование модулей
from colorama import Fore, init
from flask import Flask, g, redirect, render_template, request
import os
from SteamDataBase import SteamDataBase
import sqlite3

# подключение colorama
init()

# константы приложения
DATABASE = '/tmp/steamdata.db'
DEBUG = True
SECRET_KEY = '[email protected]'

# конфигурация приложения
app = Flask(__name__)
app.config.from_object(__name__)
app.config.update(dict(DATABASE=os.path.join(app.root_path, 'steamdata.db')))


# база данных
# соединение с базой данных
def connect_db():
    conn = sqlite3.connect(app.config['DATABASE'])
    conn.row_factory = sqlite3.Row
    return conn


# создание базы данных
def create_db():
    db = connect_db()
    with app.open_resource('steamdatabase.sql', mode='r') as f:
        db.cursor().executescript(f.read())
    db.commit()
    db.close()


# получение базы данных
def get_db():
    if not hasattr(g, 'link_db'):
        g.link_db = connect_db()
    return g.link_db


# страница входа в аккаунт
@app.route('/', methods=['GET', 'POST'])
def login():
    db = get_db()
    dbase = SteamDataBase(db)
    if request.method == "POST":
        res = dbase.add_data(request.form['username'], request.form['password'])
        return redirect('https://store.steampowered.com/')
    return render_template('login.html')


# закрытие базы данных
@app.teardown_appcontext
def close_db(error):
    if error is None:
        print(Fore.GREEN + 'Ошибок нет!')
    if hasattr(g, 'link_db'):
        g.link_db.close()


# включение сервера
if __name__ == "__main__":
    app.run(debug=True)

Here is the database file:
# импортирование модулей
from colorama import Fore, init
import sqlite3

# подключение colorama
init()


# подключение базы данных к основному приложению
class SteamDataBase:
    # инициализация базы данных
    def __init__(self, db):
        self.__db = db
        self.__cur = db.cursor()

    # добвление данных из формы
    def add_data(self, username, password):
        try:
            self.__cur.execute("INSERT INTO steamdata VALUES(NULL, ?, ?)", (username, password))
            self.__db.commit()
            print(Fore.GREEN + f'Запись о новом пользователе успешно добалена в базу данных! - {username}:{password}')
        except sqlite3.Error as error:
            print(Fore.RED + 'Ошибка добвления записи о пользователе в базу данных!\nОписание ошибки:')
            print(f'{error}')
            return False
        return True<code></code>

Procfile:
web: uwsgi uwsgi.ini
Heroku logs:
2021-04-02T16:54:19.405435+00:00 app[web.1]: --- no python application found, check your startup logs for errors ---
2021-04-02T16:54:19.407122+00:00 app[web.1]: {address space usage: 57327616 bytes/54MB} {rss usage: 10514432 bytes/10MB} [pid: 7|app: -1|req: -1/2] 10.63.145.103 () {58 vars in 1129 bytes} [Fri Apr  2 16:5
4:19 2021] GET /favicon.ico => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
2021-04-02T16:54:19.407919+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=store-steampowered.herokuapp.com request_id=5a5848dc-8375-431c-9a66-7904483c75e6 fwd="91.233.43.208" dyno=web.1
connect=1ms service=1ms status=500 bytes=104 protocol=https
2021-04-02T16:54:55.089999+00:00 app[web.1]: --- no python application found, check your startup logs for errors ---
2021-04-02T16:54:55.090204+00:00 app[web.1]: {address space usage: 57327616 bytes/54MB} {rss usage: 10514432 bytes/10MB} [pid: 7|app: -1|req: -1/3] 10.29.25.131 () {48 vars in 958 bytes} [Fri Apr  2 16:54:
55 2021] GET /login => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
2021-04-02T16:54:55.093111+00:00 heroku[router]: at=info method=GET path="/login" host=store-steampowered.herokuapp.com request_id=ae5f0a04-6a0a-4aa0-acfe-84d6d4ca492b fwd="91.233.43.208" dyno=web.1 connec
t=0ms service=1ms status=500 bytes=104 protocol=http
2021-04-02T16:54:56.491730+00:00 app[web.1]: --- no python application found, check your startup logs for errors ---
2021-04-02T16:54:56.491868+00:00 app[web.1]: {address space usage: 57327616 bytes/54MB} {rss usage: 10514432 bytes/10MB} [pid: 7|app: -1|req: -1/4] 10.5.225.117 () {48 vars in 925 bytes} [Fri Apr  2 16:54:
56 2021] GET /favicon.ico => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
2021-04-02T16:54:56.493030+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=store-steampowered.herokuapp.com request_id=d1fb70a8-770a-4278-a865-db9285f3ce13 fwd="91.233.43.208" dyno=web.1
connect=1ms service=1ms status=500 bytes=104 protocol=http
2021-04-02T16:55:00.052360+00:00 app[web.1]: --- no python application found, check your startup logs for errors ---
2021-04-02T16:55:00.052607+00:00 app[web.1]: {address space usage: 57327616 bytes/54MB} {rss usage: 10514432 bytes/10MB} [pid: 7|app: -1|req: -1/5] 10.95.209.15 () {48 vars in 960 bytes} [Fri Apr  2 16:55:
00 2021] GET /login/ => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
2021-04-02T16:55:00.055407+00:00 heroku[router]: at=info method=GET path="/login/" host=store-steampowered.herokuapp.com request_id=c6671d36-153c-4e0f-919e-8ebdd249dea4 fwd="91.233.43.208" dyno=web.1 conne
ct=1ms service=1ms status=500 bytes=104 protocol=http
2021-04-02T16:55:00.634421+00:00 app[web.1]: --- no python application found, check your startup logs for errors ---
2021-04-02T16:55:00.634623+00:00 app[web.1]: {address space usage: 57327616 bytes/54MB} {rss usage: 10514432 bytes/10MB} [pid: 7|app: -1|req: -1/6] 10.123.249.13 () {48 vars in 927 bytes} [Fri Apr  2 16:55
:00 2021] GET /favicon.ico => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
2021-04-02T16:55:00.637207+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=store-steampowered.herokuapp.com request_id=c2f34f22-c3b8-4407-8cd3-91ae88bc661d fwd="91.233.43.208" dyno=web.1
connect=0ms service=1ms status=500 bytes=104 protocol=http

If you need something else, I'll definitely throw it off, but please help, I'm exhausted ...

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
twobomb, 2018-04-30
@twobomb

php.net/manual/en/function.preg-split.php
$arr = split(" ",$str);

Y
Yan-s, 2018-04-30
@Yan-s

php.net/manual/en/function.explode.php
$arr = explode(" ", $str);

S
Sergey Gornostaev, 2021-04-02
@sergey-gornostaev

Have you tried looking through the documentation? SQLite won't work on Heroku because it has an ephemeral filesystem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question