Flask

Flask resets the connection instead of returning a 413, when the file is to big

北战南征 提交于 2021-01-27 21:27:27
问题 When MAX_CONTENT_LENGTH is definded, Flask should return an 413, but in my case it resets the connection with this error: Error 101 (net::ERR_CONNECTION_RESET): The connection was reset. I attached a example built upon the file upload pattern from Flask. I use Chrome 15.0.874.5. import os from flask import Flask, request, redirect, url_for, send_from_directory from werkzeug import secure_filename UPLOAD_FOLDER = 'uploads/' ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif',

Split list values inside dictionary to separate dictionaries

五迷三道 提交于 2021-01-27 20:11:25
问题 I have the following json response from a flask application and am wondering how I can split it out into multiple "rows"/dicts. Output: {'class': [0.0, 1.0], 'probability': [0.8488858872836712, 0.1511141127163287]} What I desire is: [{"class": 0.0, "probability": 0.8488858872836712},{"class": 1.0, "probability": 0.1511141127163287}] I've tried something like the following but am not sure how to get both keys: {k: v for e in zip(model.classes_, probabilities[0]) for k, v in zip(('class',

Python list | How to remove parenthesis,quotes and commas in my list?

落爺英雄遲暮 提交于 2021-01-27 20:00:09
问题 From my database, I'm returning a list to be displayed into my HTML page but my list has this unwanted symbols. I tried using split() function but it wont work. How can I remove those parenthesis,commas and quotes. Thanks for you help The output is : [('cenomar',), ('cedula',), ('Birth Certificate',), ('Clearance',)] I want: [cenomar, cedula, Birth Certificate, Clearance] Here is my python function: @app.route('/') def search(): conn=psycopg2.connect("dbname='forms' user='postgres' password=

ModuleNotFoundError when attempting to import from outside of directory

允我心安 提交于 2021-01-27 19:13:59
问题 I'm working on a Flask app and attempting to run my test file but unable to do so. My current app structure is: Project ── app │ ├── __init__.py │ ├── forms.py │ ├── model.py │ ├── models.py │ ├── static │ │ ├── css │ │ ├── fonts │ │ ├── img │ │ ├── js │ │ └── uploads │ ├── templates │ │ ├── client │ │ │ ├── client-base.html │ │ │ ├── client-inventory.html │ │ │ ├── client-login.html │ │ │ ├── client-macros.html │ │ │ ├── client-main.html │ │ │ └── client-signup.html │ │ └── user │ │ ├── user

Apache + mod_wsgi + flask app: “Unable to get bucket brigade for request” error in logs

限于喜欢 提交于 2021-01-27 17:55:46
问题 I have a apache2/mod_wsgi/flask/python2.7 app. Sometimes such line appears in log file: Partial results are valid but processing is incomplete: [client 45.132.96.124:34500] mod_wsgi (pid=13920): Unable to get bucket brigade for request., referer: https://my-site.com/some_url/ What is "bucket brigade" and what this error actually means? Is it apache error or wsgi server error? What does lead to this error? If this is some unhandled exception - how to handle it and where? Thanks in advance. 回答1

Import errors with WSGI, Flask, and Apache

◇◆丶佛笑我妖孽 提交于 2021-01-27 17:52:46
问题 Totally new to python-based web apps, so I'm somewhat lost. Here is my apache error: [Wed May 08 22:41:47 2013] [error] [client 64.56.91.45] mod_wsgi (pid=23704): Target WSGI script '/home/http/public/hello/hello.wsgi' cannot be loaded as Python module. [Wed May 08 22:41:47 2013] [error] [client 64.56.91.45] mod_wsgi (pid=23704): Exception occurred processing WSGI script '/home/http/public/hello/hello.wsgi'. [Wed May 08 22:41:47 2013] [error] [client 64.56.91.45] Traceback (most recent call

Flask app not running after closing putty

最后都变了- 提交于 2021-01-27 13:27:37
问题 I am trying to make a flask web app. whenever i close my putty the website stops running and even if I make any change in the code then without running again it does not reflect on the web. 回答1: When you close putty, you are virtually closing down your app also, If you want to access it even when you close down your putty, you should have "tmux installed on you system": pip install tmux Once installed, create a new tmux session by tmux new -s myname Under this session run any code you want

Catch session expiration in Flask

北慕城南 提交于 2021-01-27 07:50:52
问题 In Flask I'm using app.permanent_session_lifetime to force a session timeout. Is there a way to receive a callback before the session expires so I can perform cleanup? Looking through the documentation I don't see a corresponding Signal. 来源: https://stackoverflow.com/questions/27449819/catch-session-expiration-in-flask

cannot get environment variables set in Flask application

浪尽此生 提交于 2021-01-27 07:21:03
问题 I tried to set up sensitive information as environment variables in CentOS, and pass them to Flask config file used in main file, i.e. init .py . But it did not work. The Flask application is running under Apache. I first edit /etc/environment as root user MAIL_USERNAME="abcde@abc.com" then logout, login again Then verify MAIL_USERNAME is set by running echo $MAIL_USERNAME This works fine And in configuration.py, this is how I set MAIL_USERNAME. MAIL_USERNAME = os.environ.get('MAIL_USERNAME')

cannot get environment variables set in Flask application

十年热恋 提交于 2021-01-27 07:18:23
问题 I tried to set up sensitive information as environment variables in CentOS, and pass them to Flask config file used in main file, i.e. init .py . But it did not work. The Flask application is running under Apache. I first edit /etc/environment as root user MAIL_USERNAME="abcde@abc.com" then logout, login again Then verify MAIL_USERNAME is set by running echo $MAIL_USERNAME This works fine And in configuration.py, this is how I set MAIL_USERNAME. MAIL_USERNAME = os.environ.get('MAIL_USERNAME')