A
A
Anton Biryukov2018-07-21 19:33:23
Python
Anton Biryukov, 2018-07-21 19:33:23

When searching in a json file, it gives a 500 error?

Good evening everyone. Guys please help me with this problem.
There is a form for searching data from a json file. So the problem is that when the json file is small everything works. When I do a search in the full file, I get a 500 Intervall Server Error 500 error.
The volume of the json file is 274 mb.
The search goes on locally, but not on the server. I suspect that the problem may be in the capacity of the server. But maybe I'm doing something wrong.
Here is the py file code

from flask import Flask

from flask import render_template, request, Response, send_from_directory

import json

import logging

from logging.handlers import RotatingFileHandler
import os



app = Flask(__name__)






path = 'data2.json'

@app.route('/', methods=['GET', 'POST'])
def hello_world():
    if request.method == 'POST':
        medi_metall = request.form['num_st']

        with open(path, 'r') as f:
            data = json.loads(f.read())
            for i in data:
                if i['katid'] == medi_metall:

                    ss = 'Кадастровый номер: ' + i['katid']
                    ss1 = 'Вид использования по документу: ' + i['vidiz']
                    ss2 = 'Площадь: ' + str(i['pl']) + ' кв. м.'
                    ss3 = 'Адрес:' + i['adres']
                    ss4 = 'Предварительная стоимость: ' + str(i['prrez']) + ' руб.'

                    return render_template('index.html', tt=ss, tt1=ss1, tt2=ss2, tt3=ss3, tt4=ss4)





    return render_template('index.html')



@app.route('/1.html', methods=['GET', 'POST'])
def send():

    if request.method == 'POST':
        medi_metall = request.form['num_st']
        with open(path, 'r') as f:
            data = json.loads(f.read())
            for i in data['employees']['employee']:
                if i['FIELD2'] == medi_metall:

                    ss ='По данному номеру заказ из приложения уже был сделан'
                    return render_template('1.html', tt1=ss)
                    break
                else:
                    ss ='Данный клиент заказывает впервые';
                    return render_template('1.html', tt1=ss)


    return render_template('1.html')


if __name__ == '__main__':
    app.run()
    if not app.debug:
        # ...

        if not os.path.exists('logs'):
            os.mkdir('logs')
        file_handler = RotatingFileHandler('logs/microblog.log', maxBytes=10240,
                                           backupCount=10)
        file_handler.setFormatter(logging.Formatter(
            '%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]'))
        file_handler.setLevel(logging.INFO)
        app.logger.addHandler(file_handler)
        app.logger.setLevel(logging.INFO)
        app.logger.info('Microblog startup')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2018-07-21
@dimonchik2013

little code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question