werkzeug

104, 'Connection reset by peer' socket error, or When does closing a socket result in a RST rather than FIN?

混江龙づ霸主 提交于 2019-11-26 12:11:12
问题 We\'re developing a Python web service and a client web site in parallel. When we make an HTTP request from the client to the service, one call consistently raises a socket.error in socket.py, in read: (104, \'Connection reset by peer\') When I listen in with wireshark, the \"good\" and \"bad\" responses look very similar: Because of the size of the OAuth header, the request is split into two packets. The service responds to both with ACK The service sends the response, one packet per header

Get IP address of visitors using Flask for Python

亡梦爱人 提交于 2019-11-26 10:04:34
I'm making a website where users can log on and download files, using the Flask micro-framework (based on Werkzeug ) which uses Python (2.6 in my case). I need to get the IP address of users when they log on (for logging purposes). Does anyone know how to do this? Surely there is a way to do it with Python? See the documentation on how to access the Request object and then get from this same Request object, the attribute remote_addr . Code example from flask import request from flask import jsonify @app.route("/get_my_ip", methods=["GET"]) def get_my_ip(): return jsonify({'ip': request.remote

Capture arbitrary path in Flask route

夙愿已清 提交于 2019-11-26 06:39:44
问题 I have a simple Flask route that I want to capture a path to a file. If I use <path> in the rule, it works for /get_dir/one but not /get_dir/one/two . How can I capture an arbitrary path, so that path=\'/one/two/etc will be passed to the view function? @app.route(\'/get_dir/<path>\') def get_dir(path): return path 回答1: Use the path converter to capture arbitrary length paths: <path:path> will capture a path and pass it to the path argument. The default converter captures a single string but

Get raw POST body in Python Flask regardless of Content-Type header

北慕城南 提交于 2019-11-26 06:14:47
问题 Previously, I asked How to get data received in Flask request because request.data was empty. The answer explained that request.data is the raw post body, but will be empty if form data is parsed. How can I get the raw post body unconditionally? @app.route(\'/\', methods=[\'POST\']) def parse_request(): data = request.data # empty in some cases # always need raw data here, not parsed form data 回答1: Use request.get_data() to get the raw data, regardless of content type. The data is cached and

Is the server bundled with Flask safe to use in production?

我的未来我决定 提交于 2019-11-26 04:39:41
问题 Is the server bundled with Flask safe for deployment in a production environment? If not, what should I use to deploy Flask in production? 回答1: No . The bundled server is a development server. It's not designed with production environments in mind. It will not handle more than one request at a time by default. If you leave debug mode on and an error pops up, it opens up a shell that allows for arbitrary code to be executed on your server (think os.system('rm -rf /') ). The development server

Flask reloader crashes with “no module named Scripts\flask” on Windows

强颜欢笑 提交于 2019-11-26 01:08:53
问题 When I run flask run on Windows, I get the following error C:\\Python37\\python.exe: No module named C:\\Python37\\Scripts\\flask This was working previously, the issue started after I created a new env recently. 回答1: This was a bug introduced in Werkzeug 0.15.5. Upgrade to at least Werkzeug 0.15.6, which contains the fix. You can also run with python -m flask run instead to work around it. 来源: https://stackoverflow.com/questions/57114348/flask-reloader-crashes-with-no-module-named-scripts

Get the data received in a Flask request

给你一囗甜甜゛ 提交于 2019-11-25 22:52:27
问题 I want to be able to get the data sent to my Flask app. I\'ve tried accessing request.data but it is an empty string. How do you access request data? @app.route(\'/\', methods=[\'GET\', \'POST\']) def parse_request(): data = request.data # data is empty # need posted data here The answer to this question led me to ask Get raw POST body in Python Flask regardless of Content-Type header next, which is about getting the raw data rather than the parsed data. 回答1: The docs describe the attributes

Configure Flask dev server to be visible across the network

血红的双手。 提交于 2019-11-25 22:20:24
问题 I\'m not sure if this is Flask specific, but when I run an app in dev mode ( http://localhost:5000 ), I cannot access it from other machines on the network (with http://[dev-host-ip]:5000 ). With Rails in dev mode, for example, it works fine. I couldn\'t find any docs regarding the Flask dev server configuration. Any idea what should be configured to enable this? 回答1: While this is possible, you should not use the Flask dev server in production. The Flask dev server is not designed to be

【Python Werkzeug】 -- 2019-08-07 10:53:44

早过忘川 提交于 2019-11-25 20:19:19
原创: http://106.13.73.98/__/125/ 首先, Werkzeug 是一个 WSGI工具包 ,它可以作为一个Web框架的底层库。 需要注意的是,Werkzeug不是一个web服务器,也不是一个web框架,而是一个工具包,官方的介绍说是一个 WSGI 工具包,它可以作为一个 Web 框架的底层库,因为它封装好了很多 Web 框架的东西,例如 Request 、 Response 等等。 下面我们将使用Werkzeug来创建一个简单的web服务器,来说明Werkzeug怎么使用。 安装: pip install Werkzeug from werkzeug.wrappers import Response, Request from werkzeug.serving import run_simple @Request.application def app(request): print(request) # <Request 'http://127.0.0.1:8000/favicon.ico' [GET]> print(request.method) # 请求类型 print(request.path) # /favicon.ico return Response('Hello Werkzeug') run_simple(hostname='127.0.0