bottle

Is there a way to automatically generate REST API JSON description from Bottle routes

强颜欢笑 提交于 2020-01-05 09:32:05
问题 In case of I'm having this code: class MyApp(): def __init__(self): self.bottle = Bottle() self.bottle.route('/')(self.show_api) self.bottle.route('/api/')(self.show_api) self.bottle.route('/api/item', method='PUT')(self.save_item) def show_api(self): return <JSON representation of the API?> Is it possible to get a REST API documentation in JSON format from that? fro some reason self.bottle.routes didn't return anything useful. Thanks! 回答1: Actually the right way to generate the JSON API

Can I use python-social-auth in my `bottle app?

此生再无相见时 提交于 2020-01-04 06:51:46
问题 I am going to add a SSO button to my web appication. I want to use python-social-auth for it. But the supported web frameworks are Django, Flask, Pyramid, Tornado, CherryPy and webpy. It seems to not support Bottle framework. How to use python-social-auth for my Bottle app? Should I create my own social-auth-app-bottle ? If it is not so simple work, which one is better: Move to Flask Don't use python-social-auth (and move to other Bottle plugins like bottle-rauth , bottle-oauthlib , etc) 回答1:

Nuitka-compiled web app raises error on exit

£可爱£侵袭症+ 提交于 2020-01-04 06:16:28
问题 I am working on a real-time 3d web application project. It is built on top of Bottle and Gevent (using bottle-websocket plugin). After compilation using Nuitka, our dev server works fine except one: raises error on Ctrl+C exit. The error output is shown below $ ./__main__.bin server Bottle v0.12.18 server starting up (using GeventWebSocketServer())... Listening on http://0.0.0.0:8080/ Hit Ctrl-C to quit. ^CKeyboardInterrupt 2019-12-20T17:05:28Z /usr/lib/python3/dist-packages/apport/report.py

Nuitka-compiled web app raises error on exit

痴心易碎 提交于 2020-01-04 06:14:22
问题 I am working on a real-time 3d web application project. It is built on top of Bottle and Gevent (using bottle-websocket plugin). After compilation using Nuitka, our dev server works fine except one: raises error on Ctrl+C exit. The error output is shown below $ ./__main__.bin server Bottle v0.12.18 server starting up (using GeventWebSocketServer())... Listening on http://0.0.0.0:8080/ Hit Ctrl-C to quit. ^CKeyboardInterrupt 2019-12-20T17:05:28Z /usr/lib/python3/dist-packages/apport/report.py

How to serve static file with a hebrew name in python bottle?

五迷三道 提交于 2020-01-04 02:07:12
问题 I receive a request from the client to download some file from the server. The filename is in Hebrew. @bottle.get("/download/<folder_name>/<file_name>") def download(folder_name, file_name): file_name = file_name.decode('utf-8') folder_name = folder_name.decode('utf-8') if os.path.exists(os.path.join(folder_name, file_name)): return bottle.static_file(file_name, root=folder_name, download=True) The last line fails : return bottle.static_file(file_name, root=folder_name, download=True) I get

Bottle + Apache + WSGI + Sessions

旧时模样 提交于 2020-01-03 03:52:05
问题 I'm trying to use sessions on a small CMS that I'm working on. I'm testing, and I able to run sessions nicely using bottle as server. Code below: # test.session.py import bottle from beaker.middleware import SessionMiddleware session_opts = { 'session.type': 'file', 'session.cookie_expires': 300, 'session.data_dir': './data', 'session.auto': True } app = SessionMiddleware(bottle.app(), session_opts) @bottle.route('/set_session') def session_test(): varsession = bottle.request.environ.get(

how to redirect to particular url on 404

流过昼夜 提交于 2020-01-02 11:38:53
问题 @error(404) def error404(error): return 'Nothing here, sorry' This is the way to response 404 in bottle framework . But On 404 I want to redirect to particular url say http://abc.com/. Is it possible? 回答1: @error(404) def error404(error): from bottle import redirect # maybe test the error to see where you want to go next? redirect(new_url, 303) # HTTP 303 should be used in this case EDIT I'm not 100% sure this can be done, and I can't test it right now, but I'll test it later and update the

Access the response object in a bottlepy after_request hook

只谈情不闲聊 提交于 2019-12-30 20:38:57
问题 I have the following web app: import bottle app = bottle.Bottle() @app.route('/ping') def ping(): print 'pong' return 'pong' @app.hook('after_request') def after(): print 'foo' print bottle.response.body if __name__ == "__main__": app.run(host='0.0.0.0', port='9999', server='cherrypy') Is there a way to access the response body before sending the response back? If I start the app and I query /ping , I can see in the console that the ping() and the after() function run in the right sequence $

Binary file download

我的未来我决定 提交于 2019-12-30 18:31:14
问题 I'm building a server using python and bottle. How can I handle a request for a binary file? I have read that I should use flask. There is a way for doing that without using flask? 回答1: Yes, you should use static_file function: from bottle import static_file @route('/download/<filename:path>') def download(filename): return static_file(filename, root='/path/to/static/files', download=filename) 来源: https://stackoverflow.com/questions/13725417/binary-file-download

Nginx - Rewrite the request_uri before uwsgi_pass

橙三吉。 提交于 2019-12-29 03:58:08
问题 I have a Nginx vhost than is configured as such: ... location /one { include uwsgi_params; uwsgi_pass unix:///.../one.sock; } location /two { include uwsgi_params; uwsgi_pass unix:///.../two.sock } ... This is a simplified configuration of course When I request /one/something I would like my Python script to receive /something as request_uri . I'm using BottlePy but would like this to be handled by Nginx and not in my Python code. Can I do something like uwsgi_param REQUEST_URI replace(