werkzeug

How do I safely get the user's real IP address in Flask (using mod_wsgi)?

旧时模样 提交于 2019-12-12 07:09:10
问题 I have a flask app setup on mod_wsgi/Apache and need to log the IP Address of the user. request.remote_addr returns "127.0.0.1" and this fix attempts to correct that but I've found that Django removed similar code for security reasons. Is there a better way to safely get the user's real IP address? EDIT: Maybe I'm missing something obvious. I applied werkzeug's/Flask's fix but it doesn't seem to make a difference when I try a request with altered headers: run.py: from werkzeug.contrib.fixers

How can I exit uWsgi worker (python werkzeug) from internal error?

╄→尐↘猪︶ㄣ 提交于 2019-12-12 03:23:54
问题 I have a RESTful API written in python using werkzeug. It runs with nginx/uWsgi. I would like to kill worker process when an internal error (LOST zookeeper session) occurs and let uWsgi will spawn a new worker. If I call sys.exit(0), worker does not exit. Perhaps SystemExit or Exception is being caught somewhere. I am running as a service using init script with, exec $root/run uwsgi --socket 127.0.0.1:3037 --master --workers 4 --threads 10 --harakiri 60 --die-on-term --thunder-lock --lazy

Can't post Flask form data for testing (FieldList) [DeprecationWarning]

半城伤御伤魂 提交于 2019-12-11 10:48:42
问题 I'm writing several different flask forms. So far, what I've done to test the routes that I use with those forms is. Creating the form object Populating the form Posting the form data For example, this works (short version of the class): class RequestForm(FlaskForm): project = SelectField(label='Project', id='project', coerce=str) name = StringField('Environment Name', id='env_name', validators=[DataRequired()]) requested_by = StringField('Requested By', validators=[DataRequired()]) tag =

Flask / Werkzeug - sockets stuck in CLOSE_WAIT

你说的曾经没有我的故事 提交于 2019-12-11 09:49:08
问题 I've run into a situation where an API built on Flask-Restul intermittently becomes non-responsive. Currently it's running from Werkzeug (which I'm aware is for non-production use only) and single threaded. To complicate things a little further this is also all wrapped up inside axscript within another application. When non-responsive, a significant number of sockets show in the CLOSE_WAIT so there's something not being handled correctly during a client initiated socket teardown. As this is

Flask + sqlalchemy advanced logging

老子叫甜甜 提交于 2019-12-11 04:26:51
问题 I found a few other posts on this but none that worked for me yet so I wanted to reach out and see if anyone could explain how to properly get / redirect / set handlers on some of the loggers present in Flask / Werkzeurg / sqlalchemy. Research prior that could not answer my question: https://github.com/pallets/flask/issues/1359 http://flask.pocoo.org/docs/dev/logging/ https://gist.github.com/ibeex/3257877 My configurations: main.py ... def init_app(): """ Runs prior to app launching, contains

Google App Engine Standard dev_appserver.py giving a Import Error

杀马特。学长 韩版系。学妹 提交于 2019-12-11 03:37:37
问题 I am trying to run dev_appserver.py on this Google App Engine Standard Flask Sample As the instructions say I run: pip install -t lib -r requirements.txt dev_appserver.py app.yaml I should be able to go to http://localhost:8080/form but I get ImportError: No module named msvcrt . I found that using Flask==0.10.1 and Werkzeug==0.12.2 works but nothing newer. Versions: OS: Windows 10 Pro Python 2.7.14 Google Cloud SDK 182.0.0 app-engine-go app-engine-python 1.9.63 app-engine-python-extras 1.9

Specifying the Flask reload watch list (extra_files) in code or the `flask run` command

廉价感情. 提交于 2019-12-11 02:20:47
问题 I have some Flask applications which I run by setting the FLASK_APP environment variable and invoking flask run . Since FLASK_DEBUG is also set, the application conveniently reloads whenever I change some code. But not all code. There are other files, namely config files that I load with app.config.from_pyfile, that I want the app to watch too, so it reloads if I change those. How can I do that? I know I can specify extra_files in the built-in Werkzeug server if I invoke it from code. But as

What's the best way to disable the default /console route in Flask debug mode?

牧云@^-^@ 提交于 2019-12-10 21:27:48
问题 I want my application's dashboard area to be called /console. However, Flask uses werkzeug.debug.DebuggedApplication (http://werkzeug.pocoo.org/docs/debug/), which uses /console as the default Debug path. Flask itself only has the debug flag, app.run(debug=True) with no other options to override that path. What are my options? I temporarily added the following, but I'd rather not have to do that because I have some intricate thing's going on in JS on the front-end, like a redirect during

Django manage.py runserver throws ImportError: AdminMediaHandler

守給你的承諾、 提交于 2019-12-10 20:24:19
问题 The Problem When I run python manage.py runserver I get the error ImportError: cannot import name AdminMediaHandler . ex. (venv)agconti@agconti-Inspiron-5520:~/my_dev/github/stamped/stamped_project$ python manage.py runserver ImportError: cannot import name AdminMediaHandler This just started to happen after I installed the django-werkzeug-debugger-runserver. Im using virtualenv. Here is what I have installed: Django==1.5.2 Werkzeug==0.9.3 argparse==1.2.1 django-extensions==1.1.1 django

Embedding a Python web-based shell (Werkzeug?)

橙三吉。 提交于 2019-12-10 19:18:38
问题 I'm looking for a way to embed a python interpreter in a web page. Specifically, something similar to a textarea/REPL having access to the scope of a Django template. Werkzeug Does something similar, but I'm unable to find any example or documentation regarding the embedding process. Help is very welcome! 回答1: If you are using Apache/mod_wsgi, all you need to do is modify your .wsgi file to include: from werkzeug.debug import DebuggedApplication and application = get_wsgi_application()