bottle

Bottle.py error routing

五迷三道 提交于 2019-12-04 16:46:31
问题 Bottle.py ships with an import to handle throwing HTTPErrors and route to a function. Firstly, the documentation claims I can (and so do several examples): from bottle import error @error(500) def custom500(error): return 'my custom message' however, when importing this statement error is unresolved but on running the application ignores this and just directs me to the generic error page. I found a way to get around this by: from bottle import Bottle main = Bottle() @Bottle.error(main, 500)

Convert mongodb return object to dictionary

怎甘沉沦 提交于 2019-12-04 15:15:15
问题 I'm using the bottle framework together with mongoengine. I have an orders model : class OrderDetail(Option): orderDetailsQty = FloatField() def to_dict(self): return mongo_to_dict_helper(self) class Order(Document): userName = StringField(required=True) orderDate = DateTimeField() orderStatus = ListField(EmbeddedDocumentField(Status)) orderDetails = ListField(EmbeddedDocumentField(OrderDetail)) orderComments = ListField(EmbeddedDocumentField(Comment)) isActive = BooleanField() def to_dict

Error 2006: “MySQL server has gone away” using Python, Bottle Microframework and Apache

霸气de小男生 提交于 2019-12-04 13:54:14
问题 After accessing my web app using: - Python 2.7 - the Bottle micro framework v. 0.10.6 - Apache 2.2.22 - mod_wsgi - on Ubuntu Server 12.04 64bit; I'm receiving this error after several hours: OperationalError: (2006, 'MySQL server has gone away') I'm using MySQL - the native one included in Python. It usually happens when I don't access the server. I've tried closing all the connections, which I do, using this: cursor.close() db.close() where db is the standard MySQLdb.Connection() call. The

Bottle.py HTTP Auth?

微笑、不失礼 提交于 2019-12-04 08:27:39
问题 How can I get my bottle.py app (Running in Paste or Cherrypy) to do HTTP (basic or digest) authentication? - I need to secure it, but cant find a any HOWTOs. 回答1: bottle has a built in auth_basic decorator that can be used on a view: from bottle import auth_basic, request, route def check(user, pw): # Check user/pw here and return True/False @route('/') @auth_basic(check) def home(): return { 'data': request.auth } 回答2: There are some libraries on GitHub like https://github.com

Is it possible to use gzip compression with Server-Sent Events (SSE)?

谁说胖子不能爱 提交于 2019-12-04 05:46:20
I would like to know if it is possible to enable gzip compression for Server-Sent Events (SSE ; Content-Type: text/event-stream). It seems it is possible, according to this book: http://chimera.labs.oreilly.com/books/1230000000545/ch16.html But I can't find any example of SSE with gzip compression. I tried to send gzipped messages with the response header field Content-Encoding set to "gzip" without success. For experimenting around SSE, I am testing a small web application made in Python with the bottle framework + gevent ; I am just running the bottle WSGI server: @bottle.get('/data_stream')

Python bottle requests and unicode

时间秒杀一切 提交于 2019-12-04 03:51:34
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 decoding these elements with a different encoding or do I? Is there a general option for bottle to store

Start a wsgi app from within virtualenv as a Linux system service

余生颓废 提交于 2019-12-03 20:23:58
I'm currently developing a bottle app within virtualenv. I intend to serve it using bjoern WSGI server (but that probably doesn't matter too much). I also intend to serve the app with a lighty or nginx reverse proxy. Anyhow, can the app be run from within its own virtualenv as a system service? And if so, how would one go about it? According to my experience, I suggest that you can use Supervisord to run your web server as daemon service. Although you can write some Linux service scripts in /etc/init.d, but they are really difficult to do it correctly. Here is an example init.d script for

Bottle web app not serving static css files

早过忘川 提交于 2019-12-03 15:23:32
My bottle web application is not serving my main.css file despite the fact I am using the static_file method. app.py from bottle import * from xml.dom import minidom @route('/') def index(): return template("index") @route('/glossaryXML') def glossary(): doc_def = minidom.parse("table_definitions.xml") terms = doc_def.getElementsByTagName("str_term") defins = doc_def.getElementsByTagName("str_definition") return template("list", terms=terms, defins=defins) @route('<filename>.css') def stylesheets(filename): return static_file(filename, root='static') @error(404) def fourofour(error): return

is there any way to run bottle application in daemon mode

余生长醉 提交于 2019-12-03 15:14:13
问题 I have a web application built on bottle(python) frame work and I want to run it in daemon mode.Is there any way to run it in daemon mode Thanks 回答1: Sure you can. Install BottleDaemon 0.1.0 on your OS and than change your router file like so: from bottledaemon import daemon_run from bottle import route @route("/hello") def hello(): return "Hello World" # The following lines will call the BottleDaemon script and launch a daemon in the background. if __name__ == "__main__": daemon_run() 来源:

Static files not loaded in a Bottle application when the trailing slash is omitted

浪子不回头ぞ 提交于 2019-12-03 14:12:51
问题 I am serving a test file through apache using Bottle. Following are my apache config: WSGIDaemonProcess temp user=www-data group=www-data processes=1 threads=5 WSGIScriptAlias /temp /opt/gridops/usage/temp/adapter.wsgi <Directory /opt/gridops/usage/temp> WSGIProcessGroup temp WSGIApplicationGroup %{GLOBAL} Order deny,allow Allow from all </Directory> adapter.wsgi : import os,sys os.chdir(os.path.dirname(__file__)) sys.path = ['/opt/gridops/usage/temp'] + sys.path os.chdir(os.path.dirname(_