TL;DR: If the requests are not cached, you likely want to use zlib and declare Content-Encoding to be 'deflate'. That change alone should make your code work. If you declare Content-Encoding to be gzip, you need to actually use gzip. They are based on the the same compression algorithm, but...

some processes launched via "spyder 2.3.4 version in Winpython" in a separate process don't want to die when they should. I'm really not sure where is the problem, but your issue looks a little bit like mine, so: bottle and Windows seem not the guilty guys. spyder 2.3.5 or recent...

Set the correct logging level (at least ERROR if you want to get all messages with level ERROR or higher) and add a handler to write all messages into a file. For more details have a look at https://docs.python.org/2/howto/logging-cookbook.html.

If you're not in DEBUG mode, then Bottle is caching your rendered template. Couple of things: Turn debug mode on and see if that helps. bottle.debug(True) before you run the server. (EDIT: I hadn't noticed earlier that you're already using debug mode. Leaving this item here anyway for reference.) Do...

No. An HTTP form submission contains only the name and the value of each form field. Put the ID into the value (along with any other value you need to have there). Ideally the ID and the value would be the same, or similar enough that you can easily derive...

I think the problem is in the template side, when you render the vals argument. The rendered vals must be valid JavaScript code. By default, bottle auto-escapes HTML special characters, being single and double quotes among them. So, when you pass the Python list_vals list to the template function, it...

Can you please try it and let me know By using pool_recycle I think you can over come it. http://docs.sqlalchemy.org/en/rel_0_9/dialects/mysql.html#connection-timeouts replace engine = create_engine(mysql_connect_string) by engine = create_engine(mysql_connect_string, pool_size=100, pool_recycle=280) Connection Timeouts MySQL features an automatic connection close behavior, for connections that have been idle for eight hours or more....

I'm not particularly familiar with networkx, but it appears to take an ax kwarg that specifies the Axes object to draw on. In your case, that would be your P object, returned by fig.add_subplot. Typically, code that does that looks something like: def blah(data, ax=None): if ax is None: ax...

I posted the solution to the updated situation mentioned above here: How to mongodump from OpenShift and mongorestore locally on MongoDB 2.4.9? The data corruption was caused from exporting and importing with RockMongo - apparently sometimes there can be issues with this approach and larger data sets. ...

In essence HTML is text. Each time the browser makes a request (for example to http://localhost:8080/login or www.domain.com/route) some server has to serve this html text document. If your HTML never changes(static website) then you don't need Python. But if you need to generate new HTML for new requests (for...

Your problem stems from some confusion with the bottle app. Bottle creates a default app for you whenever you use @route (more on this), and reuses this default app implicitly on subsequent calls. This default app behavior is present in many functions (including hook and run). The point is: app...

Welcome to Bottle and to Python. :) Looking at the Bottle source code, the problem is readily apparent. Look how static_file ends: def static_file(...): ... return HTTPResponse(body, **headers) static_file creates a new HTTPResponse object--so any headers you've set before then will be discarded. A very simple way around this is...

An URL using the file procotol is never requested from the server. The client (browser) always looks for it on the local system. So it doesn't matter how you configure your Bottle application, the browser will not ask it for such an URL. If you want the Botte application to...

A name of a function doesn't mean anything to Bottle, but only as long as you provide a path (or paths) to route decorator. Arguments to Route's constructor include callback and rule, where callback is your function and rule is a path string. If one or more paths were provided,...

HTTPError uses a predefined HTML template to build the body of the response. Instead of using HTTPError you can use response with the appropriate status code and body. import json from bottle import run, route, response @route('/text') def get_text(): response.status = 400 return 'Object already exists with that name' @route('/json')...

Well, my best option was to put that explicit javascript into a new javascript file and add its path to the html like: <script type="text/javascript" src="/<script_path_here>"></script> That way my functions that handles the static files on the .py would do their job....

Just return the bytes. (You should also set the Content-Type header.) @route('/image') def video_image(): image_buffer = BytesIO() pi_camera.capture(image_buffer, format='jpeg') # This works without a problem image_buffer.seek(0) # this may not be needed bytes = image_buffer.read() response.set_header('Content-type', 'image/jpeg') return bytes ...

You must rename your request variable to something else. Python kind of reserves the variable name request to be a local variable due to request = ... before actually executing the code. The interpreter then executes your line game_id = request.forms.get('game_id'), where request is the new reserved local variable, which...

That route is configured to return a view, not a JSON dict. If you comment out this line, then it will return a dict instead: @view('test.tpl') view renders the template only when the response is a dict. When it's a string (as in your response from json.dumps), it just passes...

Class attributes are shared among all instances of a class. What you're looking for is an instance attribute: class MyClass: def __init__(self): self.my_list = [] def add_to_list(self, var): self.my_list.append(var) See this question for more information....

row['first_name'] is unicode, you don't need to decode it. In contrast, you need to encode it when printing, and if you not, python interpreter will do it for you (For example if you are printing it to the stdout, python interpreter will encode it with sys.stdout.encoding). I got the same...

If you're rolling your own solution, you should write a simple Bottle plugin that emits log lines to a logging logger. Here's an example that sets up a basic logger, defines the logging plugin, and creates a Bottle app with that plugin installed on all routes. from bottle import Bottle,...

I'm not familiar with bottle, but for other templating engine this sort of thing is done via inheritance. For example, Imagine you have a base template called content.tpl that looks something like what you have for your layout.tpl: <html> <head> <title>{{title}}</title> </head> <body> <div id='sidebar'>%% section "sidebar" %%</div> <div id='content'>%%...

As it looks to me, you are trying to create a JavaScript file through Python. That sounds like a very awkward and inconvenient way to go about exchanging data between two worlds. A common practice to communicate between the front-end (JavaScript) and the back-end (a Python app in your case)...

You are confusing how something is stored vs. how something is displayed. In MongoDB, dates are stored as 64 bit integers, what you are seeing is the way it is represented so that we can easily determine what date and time the 64bit number represents. The ISODate is just a...

First of all 'GET' is the better alternative since you are not passing any params to your DB. Secondly on which port is your application running? You are adding 8080 to your request which lets me assume your app is running under a different port. JS is based on the...

This turns out to have nothing to do with bottle. The ultimate cause of the problem is that the client request has two Content-Type headers due to a defect in an emacs lisp HTTP library. Embarrassingly, I've known about this defect for quite some time, but I thought I'd properly...

The problem is very simply that <a href="feed.html"> has a wrong href given your URL pattern. Just change it to <a href="feed"> It's also a good idea, as BrenBarn suggested, to move the templates into their own separate subdirectories, away from the one from which you want to serve truly...

I eventually worked out what the problem is. I needed to "fake" the request environment for bottle to play nicely: from bottle import request, run, post, tob from io import BytesIO body = "abc" request.environ['CONTENT_LENGTH'] = str(len(tob(body))) request.environ['wsgi.input'] = BytesIO() request.environ['wsgi.input'].write(tob(body)) request.environ['wsgi.input'].seek(0) # Now call your route function and assert...

See the cursor.fetchall documentation: Fetches all (remaining) rows of a query result, returning a list. Note that the cursor’s arraysize attribute can affect the performance of this operation. An empty list is returned when no rows are available. Since an empty list in Python is a false-y expression this normally...

You can get the variable value by name from the locals(): {{locals()['mylist' + str(i)][0]}} Demo: >>> from bottle import template >>> template('{{locals()["list" + str(i)]}}', i=1, list1=[1,2,3,4]) u'[1, 2, 3, 4]' Personally, I don't like the solution. Better construct a context dict with mylist1, mylist2 ... mylistn as keys and actual...

Good news: You can "stack" routes quite straightforwardly. Just do this: @route("/") @route("/<url:re:.+>") def hello(url): return template('page_template', url=url) That will treat root the same as your existing regex route. As for overlapping routes, according to the documentation, dynamic routes are evaluated in the order in which they were defined....

Your code is correct, you just need to add a try/catch statement: from my_package.web_api import app from cherrypy.wsgiserver import CherryPyWSGIServer server = CherryPyWSGIServer( ('0.0.0.0', 80), app, server_name='My_App', numthreads=30) try: server.start() except KeyboardInterrupt: server.stop() You might wanna also consider to do some logging with wsgi-request-logger or something similar. This are three...

request.query['q'] and forms.get('q') return the raw byte value submitted by the web browser. The value äöü, submitted by a browser as UTF-8 encoded bytes, is '\xc3\xa4\xc3\xb6\xc3\xbc'. If you print that byte string, and the place you're printing it to interprets it as ISO-8859-1, or the similar Windows code page 1252,...

As the bottle documentation states, the request data is "a file like object". http://bottlepy.org/docs/dev/tutorial.html#the-raw-request-body So you access the raw body using read(). Also, dir is not a method of objects, it's a freestanding function which you call passing an object. dir(request.body) And googling for StringIO should have brought you here:...

I already met this behaviour answering one question and it had gotten me confused. If you would have searched around for related questions the list would go on and on. The suspect was some incorrect server-side handling of Keep-Alive, HTTP pipelining, cache policy or the like. But in fact it...

You are using if...elif.... Python will pick one matching test (the first if or elif test to match), and never run the other branches. Thus, altering progress in one of those branches will not cause one of the other branches to then be picked. If the tests are to be...

ret is already a JSON string. There is no need to call json.dumps on it. Either return ret directly, or create it as a Python dict and then dump it to JSON: ret = { "chart": { "type": "column", } } return json.dumps(ret) ...

Please refer to the documentation: timeout (optional, integer) Seconds until the session is considered invalid, after which it will be ignored and invalidated. This number is based on the time since the session was last accessed, not from when the session was created. Defaults to never expiring. ...

In your code you did not use the decorator methods for the app object in your static file and 404 error routes. So @route should be @app.route and the same for error. You also probably intended to root your static files from a relative path e.g. return static_file(filename, root='./static/') or...

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, which I thought I had, but it seems with wrong syntax. I solved it using a .env file with my foreman setup to set the variable like...

Add a /display route with POST method. In this, catch the value of beer's ID, and if the user clicked on Add or Sub. Once this is done, you got the beer ID, and the action to do, you just have to do your stuff with DB, and redirect to...

I am not familiar with Bottle, but is seems that you should end your %for loop. Maybe something along the lines of %end edit: I am surprised it would not give you some sort of template error though. That is how Flask and Django work. You labelled your post as...