bottle

How do you accept any URL in a Python Bottle server?

自闭症网瘾萝莉.ら 提交于 2019-11-30 17:53:45
Using a Bottle Sehttp://bottlepy.org/docs/dev/routing.html#wildcard-filters I'd like to accept any url, and then do something with the url. e.g. @bottle.route("/<url:path>") def index(url): return "Your url is " + url This is tricky because URLs have slashes in them, and Bottle splits by slashes. Based on new Bottle (v0.10), use a re filter: @bottle.route("/<url:re:.+>") You can do that with old parameters too: @bottle.route("/:url#.+#") I think you (OP) were on the right track to begin with. <mypath:path> should do the trick. I just tried it out with bottle 0.10 and it works: ~>python test.py

Sending JSON through requests module and catching it using bottle.py and cherrypy

北战南征 提交于 2019-11-30 16:56:26
I have a server which needs to be able to accept JSON and then process it and then send JSON back. The code at my server side is using bottle.py with cherrypy . The route in concern is the following: @route ('/tagTweets', method='POST') def tagTweets(): response.content_type = 'application/json' # here I need to be able to parse JSON send along in this request. For requesting this page and testing the functionality, I'm using requests module code: The data that I have to send is list of tweets. The data is itself fetched from some server which returns list of tweets. For fetching tweets, I'm

Sending JSON through requests module and catching it using bottle.py and cherrypy

微笑、不失礼 提交于 2019-11-30 16:18:32
问题 I have a server which needs to be able to accept JSON and then process it and then send JSON back. The code at my server side is using bottle.py with cherrypy . The route in concern is the following: @route ('/tagTweets', method='POST') def tagTweets(): response.content_type = 'application/json' # here I need to be able to parse JSON send along in this request. For requesting this page and testing the functionality, I'm using requests module code: The data that I have to send is list of

uWSGI for uploading and processing files

北城余情 提交于 2019-11-30 16:11:17
问题 I have a python web application written in bottlepy. Its only purpose is to allow people to upload large files that will be processed (takes approximately 10-15 minutes to process). The upload code i rather simple: @route('/upload', method='POST') def upload_file(): uploadfile = request.files.get('fileToUpload') if not uploadfile: abort(500, 'No file selected for upload') name,ext = os.path.splitext(uploadfile.filename) if ext not in ['.zip','.gz']: abort(500, 'File extension not allowed')

uWSGI for uploading and processing files

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 15:44:43
I have a python web application written in bottlepy. Its only purpose is to allow people to upload large files that will be processed (takes approximately 10-15 minutes to process). The upload code i rather simple: @route('/upload', method='POST') def upload_file(): uploadfile = request.files.get('fileToUpload') if not uploadfile: abort(500, 'No file selected for upload') name,ext = os.path.splitext(uploadfile.filename) if ext not in ['.zip','.gz']: abort(500, 'File extension not allowed') try: uploadfile.save('./files') process_file(uploadfile.filename) #this function is not yet implemented

Bottle.py session with Beaker

杀马特。学长 韩版系。学妹 提交于 2019-11-30 11:41:39
问题 first time questioner here. I'm currently struggling on how to use Beaker properly using the Bottle micro-framework. Here's the problematic program: #!/usr/bin/python # -*- coding: utf-8 -*- # filename: server.py import bottle as app from beaker.middleware import SessionMiddleware session_options = { 'session.type': 'file', 'session.data_dir': './session/', 'session.auto': True, } app_middlware = SessionMiddleware(app.app(), session_options) app_session = app.request.environ.get('beaker

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

纵然是瞬间 提交于 2019-11-30 11:08:37
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. 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

How can I get Bottle to restart on file change?

余生颓废 提交于 2019-11-30 10:52:02
I'm really enjoying Bottle so far, but the fact that I have to CTRL+C out of the server and restart it every time I make a code change is a big hit on my productivity. I've thought about using Watchdog to keep track of files changing then restarting the server, but how can I do that when the bottle.run function is blocking. Running the server from an external script that watches for file changes seems like a lot of work to set up. I'd think this was a universal issue for Bottle, CherryPy and etcetera developers. Thanks for your solutions to the issue! Check out from the tutorial a section

how to open a url in python

戏子无情 提交于 2019-11-30 10:11:31
问题 import urllib fun open(): return urllib.urlopen('http://example.com') But when example.com opens it does not render css or js. How can I open the webpage in a web browser? @error(404) def error404(error): return webbrowser.open('http://example.com') I am using bottle. Giving me the error: TypeError("'bool' object is not iterable",) 回答1: with the webbrowser module import webbrowser webbrowser.open('http://example.com') # Go to example.com 回答2: import webbrowser webbrowser.open(url, new=0,

Python bottle module causes “Error: 413 Request Entity Too Large”

只愿长相守 提交于 2019-11-30 06:14:40
Using Python's module bottle , I'm getting HTTP 413 error when posting requests of body size > bottle 's internal MEMFILE_MAX constant. Minimal working example is shown below. Server part ( server.py ): from bottle import * @post('/test') def test(): return str(len(request.forms['foo'])); def main(): run(port=8008); if __name__ == '__main__': main(); Client part ( client.py ): import requests def main(): url = 'http://127.0.0.1:8008/test'; r = requests.post(url, data={ 'foo' : 100000 * 'a' }); print(r.text); r = requests.post(url, data={ 'foo' : 200000 * 'a' }); print(r.text); if __name__ == '