werkzeug

IOError: No space left on device - which device?

假装没事ソ 提交于 2019-12-03 13:04:25
问题 I'm uploading a small file (8.5 Mb) to a flask test server. When the file finishes uploading, the server reports: File "/home/ubuntu/.virtualenvs/eco_app/lib/python2.7/site-packages/wtforms/form.py", line 212, in __call__ return type.__call__(cls, *args, **kwargs) File "/home/ubuntu/.virtualenvs/eco_app/lib/python2.7/site-packages/flask_wtf/form.py", line 49, in __init__ formdata = request.form File "/home/ubuntu/.virtualenvs/eco_app/lib/python2.7/site-packages/werkzeug/local.py", line 338,

Dynamic form fields in flask.request.form

时光总嘲笑我的痴心妄想 提交于 2019-12-03 12:27:42
问题 I've looked through the documentation, but for the life of me, I can't figure out how the request.form object in Flask is populated. The documentation says that it's filled with parsed form data from POST or PUT requests, but my form is dynamic so I don't necessarily know what fields exist when the POST request is sent - though I want to make sure I add the information from these fields to the database. Some of the fields in the form are always there, but there will also be any number of

Using CherryPy/Cherryd to launch multiple Flask instances

℡╲_俬逩灬. 提交于 2019-12-03 06:22:58
Per suggestions on SO/SF and other sites, I am using CherryPy as the WSGI server to launch multiple instances of a Python web server I built with Flask. Each instance runs on its own port and sits behind Nginx. I should note that the below does work for me, but I'm troubled that I have gone about things the wrong way and it works "by accident". Here is my current cherrypy.conf file: [global] server.socket_host = '0.0.0.0' server.socket_port = 8891 request.dispatch: cherrypy.dispatch.MethodDispatcher() tree.mount = {'/':my_flask_server.app} Without diving too far into my Flask server, here's

in a Flask unit-test, how can I mock objects on the request-global `g` object?

时间秒杀一切 提交于 2019-12-03 05:48:53
I have a flask application that is setting up a database connection in a before_filter , very similar to this : @app.before_request def before_request(): g.db = connect_db() Now: I am writing some unit-tests and I do not want them to hit the database. I want to replace g.db with a mock object that I can set expectations on. My tests are using app.test_client() , as is demonstrated in the flask documentation here . An example test looks something like def test(self): response = app.test_client().post('/endpoint', data={..}) self.assertEqual(response.status_code, 200) ... The tests work and pass

Flask slow at retrieving post data from request?

跟風遠走 提交于 2019-12-03 04:30:18
I'm writing flask application that accepts POST requests with json data. I noticed huge differences in response time based on data size being passed to application. After debugging I narrowed down issue to the line where I was retrieving json data from request object. It may be important to note that testing was done on flask development server. start = time.time() resp = json.dumps(request.json) return str(time.time() - start) I timed this line and for data of 1024 (probably not coincidence) and less characters this took 0.002s and for anything over 1024 over 1 second! What is happening here?

Getting the array as GET query parameters in Python

别说谁变了你拦得住时间么 提交于 2019-12-03 04:04:41
问题 I know in php I could just use $_GET['key1']['key2'] to retrieve GET data that is sent in the form of an array but is that something possible in Python as I just receive a string and it's not recognized as an array/list. I use flask/werkzeug if that matters. 回答1: The deep parsing of argument names is unique for PHP AFAIK. If you need just a simple list, just pass several parameters with the same name and use request.args.getlist(<paramname>) (documentation). Otherwise you have to parse the

IOError: No space left on device - which device?

Deadly 提交于 2019-12-03 03:18:52
I'm uploading a small file (8.5 Mb) to a flask test server. When the file finishes uploading, the server reports: File "/home/ubuntu/.virtualenvs/eco_app/lib/python2.7/site-packages/wtforms/form.py", line 212, in __call__ return type.__call__(cls, *args, **kwargs) File "/home/ubuntu/.virtualenvs/eco_app/lib/python2.7/site-packages/flask_wtf/form.py", line 49, in __init__ formdata = request.form File "/home/ubuntu/.virtualenvs/eco_app/lib/python2.7/site-packages/werkzeug/local.py", line 338, in __getattr__ return getattr(self._get_current_object(), name) File "/home/ubuntu/.virtualenvs/eco_app

Dynamic form fields in flask.request.form

半腔热情 提交于 2019-12-03 03:05:18
I've looked through the documentation, but for the life of me, I can't figure out how the request.form object in Flask is populated. The documentation says that it's filled with parsed form data from POST or PUT requests, but my form is dynamic so I don't necessarily know what fields exist when the POST request is sent - though I want to make sure I add the information from these fields to the database. Some of the fields in the form are always there, but there will also be any number of extra fields from a list of about 60. How should I go about figuring out which of these additional fields

werkzeug.routing.BuildError: Could not build url for endpoint

匿名 (未验证) 提交于 2019-12-03 01:39:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have created a web API to render a webpage with navigation. Below is my code from flask import Flask, render_template, request app = Flask(__name__) @app.route('/testsite/') def home(): return render_template('home.html') if __name__ == '__main__': app.run(debug=True) @app.route('/about/') def about(): return render_template('about.html') if __name__ == '__main__': app.run(debug=True) Below is the HTML code for both html templates home.html <!DOCTYPE html> <html> <body> {% extends "layout.html" %} {% block content %} <div class="home"> <h1

Flask/Werkzeug how to attach HTTP content-length header to file download

匿名 (未验证) 提交于 2019-12-03 01:25:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am using Flask (based on Werkzeug) which uses Python. The user can download a file, I'm using the send_from_directory -function . However when actually downloading the file, the HTTP header content-length is not set. So the user has no idea how big the file being downloaded is. I can use os.path.getsize(FILE_LOCATION) in Python to get the file size (in bytes), but cannot find a way to set the content-length header in Flask. Any ideas? 回答1: I believe you'd do something like this (untested): from flask import Response response = Response()