bottle

Catching bottle server errors

放肆的年华 提交于 2019-12-23 12:20:15
问题 I am trying to get my bottle server so that when one person in a game logs out, everyone can immediately see it. As I am using long polling, there is a request open with all the users. The bit I am having trouble with is catching the exception that is thrown when the user leaves the page from the long polling that can no longer connect to the page. The error message is here. Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/gevent/pywsgi.py", line 438, in handle_one

Bottle.py caching templates despite being in debug mode

时光毁灭记忆、已成空白 提交于 2019-12-23 11:24:05
问题 I just built my first Bottle.py app on GAE. It's working except that when I change the templates I have to restart the dev server to see the changes. The docs say that template caching is supposed to be disabled when bottle.debug(True), and that you can call bottle.TEMPLTE.clear() as well, but neither of those work. I also tried setting run(reloader=True) but that causes an error. What am I doing wrong? Does bottle.debug() work for anyone else on GAE? import bottle bottle.debug(True) bottle

Bottle.py caching templates despite being in debug mode

笑着哭i 提交于 2019-12-23 11:24:02
问题 I just built my first Bottle.py app on GAE. It's working except that when I change the templates I have to restart the dev server to see the changes. The docs say that template caching is supposed to be disabled when bottle.debug(True), and that you can call bottle.TEMPLTE.clear() as well, but neither of those work. I also tried setting run(reloader=True) but that causes an error. What am I doing wrong? Does bottle.debug() work for anyone else on GAE? import bottle bottle.debug(True) bottle

How to return error messages in JSON with Bottle HTTPError?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 10:26:08
问题 I have a bottle server that returns HTTPErrors as such: return HTTPError(400, "Object already exists with that name") When I receive this response in the browser, I'd like to be able to pick out the error message given. As it is right now I can see the error message in the response's responseText field, but it's buried in an HTML string that I'd rather not parse if I don't have to. Is there any way I can specifically set the error message in Bottle so I can pick it out in JSON in the browser?

Test bottle app without running bottle server

こ雲淡風輕ζ 提交于 2019-12-23 03:00:13
问题 I am following Recipes of bottle framework. When I try below code #filename: mywebapp.py from bottle import Bottle, run, request app = Bottle() @app.get('/hello') def hello(): return "Hello " + request.get_header('name') if __name__ == '__main__': run(app, host='localhost', port=80) Function testcase with TestApp #filename: test_mywebapp.py from webtest import TestApp import mywebapp def test_functional_hello_world(): app = TestApp(mywebapp.app) assert app.get('/hello').status_code == 200

bottle hooks with beaker session middleware and checking logins

独自空忆成欢 提交于 2019-12-22 10:24:48
问题 I'm writing a bottle application with beaker session middleware. My code is has this: @bottle.route('/') def slash(): try: beaker_session = request.environ['beaker.session'] except: #redirect('/login') abort(401, "Failed beaker_session in slash") try: name = beaker_session['name'] except: redirect('/login') for each route request except /login. I know there is a bottle hook system to do things before requests, but I'm not sure how best to use it to check if someone is logged in or not. I'm

bottle hooks with beaker session middleware and checking logins

你说的曾经没有我的故事 提交于 2019-12-22 10:19:02
问题 I'm writing a bottle application with beaker session middleware. My code is has this: @bottle.route('/') def slash(): try: beaker_session = request.environ['beaker.session'] except: #redirect('/login') abort(401, "Failed beaker_session in slash") try: name = beaker_session['name'] except: redirect('/login') for each route request except /login. I know there is a bottle hook system to do things before requests, but I'm not sure how best to use it to check if someone is logged in or not. I'm

bottle gevent and threading: gevent is only usable from a single thread

前提是你 提交于 2019-12-22 09:39:37
问题 I have a python bottle application, which uses threads. due to the fact I'm using monkey.patch, the threads were blocking app execution (a dialog box fired from a thread was blocking bottle routes from responding to the client, until dismissed.) A little research here showed I should use monkey patch without trying to patch Thread: # Patch python's threads with greenlets from gevent import monkey monkey.patch_all(thread=False) This does not block on a minimal example I wrote. But raises these

How to send xml/application format in bottle?

允我心安 提交于 2019-12-22 09:09:10
问题 If some one come to my url suppose /get it should give back a xml/application format in response in bottle framework. How can i do this? i am using elementree as xml generator. 回答1: Look on the official page for the cookie example and do it like this: @route('/xml') def xml(): response.headers['Content-Type'] = 'xml/application' ....(create the xml here)...... return xml_content_whatever 来源: https://stackoverflow.com/questions/3490744/how-to-send-xml-application-format-in-bottle

Python bottle requests and unicode

安稳与你 提交于 2019-12-21 09:59:07
问题 I'm building a small RESTful API with bottle in python and am currently experiencing an issue with character encodings when working with the request object. Hitting up http://server.com/api?q=äöü and looking at request.query['q'] on the server gets me "äöü", which is obviously not what I'm looking for. Same goes for a POST request containing the form-urlencoded key q with the value äöü . request.forms.get('q') contains "äöü". What's going on here? I don't really have the option of