bottle

Bottle file upload and process

不问归期 提交于 2019-11-28 23:54:58
I am using Bottle for uploading rather large files. The idea is that when the file is uploaded, the web app run (and forget) a system command with the uploaded file-path as an argument. Except for starting the system command with the correct file-path as an argument I do not need to save the file, but I need to be certain that the file will be available until the process completes the processing. I use the exact code described here: http://bottlepy.org/docs/dev/tutorial.html#post-form-data-and-file-uploads My questions are: Do bottle store uploaded file in memory or on a specific place on the

Bottle web framework - How to stop?

孤人 提交于 2019-11-28 23:10:55
When starting a bottle webserver without a thread or a subprocess, there's no problem. To exit the bottle app -> CTRL + c . In a thread, how can I programmatically stop the bottle web server ? I didn't find a stop() method or something like that in the documentation. Is there a reason ? For the default (WSGIRef) server, this is what I do (actually it is a cleaner approach of Vikram Pudi's suggestion): from bottle import Bottle, ServerAdapter class MyWSGIRefServer(ServerAdapter): server = None def run(self, handler): from wsgiref.simple_server import make_server, WSGIRequestHandler if self

Bottle Static files

被刻印的时光 ゝ 提交于 2019-11-28 17:48:54
问题 I have tried reading the docs for Bottle, however, I am still unsure about how static file serving works. I have an index.tpl file, and within it it has a css file attached to it, and it works. However, I was reading that Bottle does not automatically serve css files, which can't be true if the page loads correctly. I have, however, run into speed issues when requesting the page. Is that because I didn't use the return static_file(params go here) ? If someone could clear up how they work, and

Streaming file upload using bottle (or flask or similar)

Deadly 提交于 2019-11-28 16:55:11
I have a REST frontend written using Python/Bottle which handles file uploads, usually large ones. The API is wirtten in such a way that: The client sends PUT with the file as a payload. Among other things, it sends Date and Authorization headers. This is a security measure against replay attacks -- the request is singed with a temporary key, using target url, the date and several other things Now the problem. The server accepts the request if the supplied date is in given datetime window of 15 minutes. If the upload takes long enough time, it will be longer than the allowed time delta. Now,

How to load a javascript or css file into a BottlePy template?

心不动则不痛 提交于 2019-11-28 04:46:36
I am trying to return a html template with BottlePy. And this works fine. But if I insert a javascript file like this in my tpl-file: <script type="text/javascript" src="js/main.js" charset="utf-8"></script> I get an 404 error. (Failed to load resource: the server responded with a status of 404 (Not Found)) Does anyone know how to fix this problem? Here is my script file: from bottle import route, run, view @route('/') @view('index') def index(): return dict() run(host='localhost', port=8080) And that is the template file, located in "./views" subfolder. <!DOCTYPE html> <html lang="de"> <head>

Bottle framework and OOP, using method instead of function

送分小仙女□ 提交于 2019-11-28 03:34:28
I've done some coding with Bottle. It's really simple and fits my needs. However, I got stick when I tried to wrap the application into a class : import bottle app = bottle class App(): def __init__(self,param): self.param = param # Doesn't work @app.route("/1") def index1(self): return("I'm 1 | self.param = %s" % self.param) # Doesn't work @app.route("/2") def index2(self): return("I'm 2") # Works fine @app.route("/3") def index3(): return("I'm 3") Is it possible to use methods instead of functions in Bottle? Your code does not work because you are trying to route to non-bound methods. Non

NGINX + uWSGI Connection Reset by Peer

自古美人都是妖i 提交于 2019-11-27 22:26:59
I'm trying to host Bottle Application on NGINX using uWSGI. Here's my nginx.conf location /myapp/ { include uwsgi_params; uwsgi_param X-Real-IP $remote_addr; uwsgi_param Host $http_host; uwsgi_param UWSGI_SCRIPT myapp; uwsgi_pass 127.0.0.1:8080; } I'm running uwsgi as this uwsgi --enable-threads --socket :8080 --plugin python -- wsgi-file ./myApp/myapp.py I'm using POST Request. For that using dev Http Client. Which goes infinite when I send the request http://localhost/myapp uWSGI server receives the request and prints [pid: 4683|app: 0|req: 1/1] 127.0.0.1 () {50 vars in 806 bytes} [Thu Oct

How do I return a JSON array with Bottle?

我们两清 提交于 2019-11-27 20:27:51
I'm writing an API using Bottle , which so far has been fantastic. However, I've run up against a small hurdle when trying to return a JSON array. Here's my test app code: from bottle import route, run @route('/single') def returnsingle(): return { "id": 1, "name": "Test Item 1" } @route('/containsarray') def returncontainsarray(): return { "items": [{ "id": 1, "name": "Test Item 1" }, { "id": 2, "name": "Test Item 2" }] } @route('/array') def returnarray(): return [{ "id": 1, "name": "Test Item 1" }, { "id": 2, "name": "Test Item 2" }] run(host='localhost', port=8080, debug=True, reloader

Streaming file upload using bottle (or flask or similar)

梦想的初衷 提交于 2019-11-27 20:00:07
问题 I have a REST frontend written using Python/Bottle which handles file uploads, usually large ones. The API is wirtten in such a way that: The client sends PUT with the file as a payload. Among other things, it sends Date and Authorization headers. This is a security measure against replay attacks -- the request is singed with a temporary key, using target url, the date and several other things Now the problem. The server accepts the request if the supplied date is in given datetime window of

Is there a way to log python print statements in gunicorn?

隐身守侯 提交于 2019-11-27 17:31:36
问题 With my Procfile like this: web: gunicorn app:app \ --bind "$HOST:$PORT" \ --debug --error-logfile "-" \ --enable-stdio-inheritance \ --reload \ --log-level "debug" is it in any way possible to get python print statements to be logged to stdout / bash? I am using the bottle framework here as well, if that affects anything. 回答1: It turns out the print statements were actually getting through, but with delay. The gunicorn docs for --enable-stdio-inheritance note to set the PYTHONUNBUFFERED ,