cherrypy

Silencing cherrypy

被刻印的时光 ゝ 提交于 2019-12-23 13:08:47
问题 I have a cherrypy server distributing xml files to webpages. While my server runs, cherrypy offers logs for each webpage that has been requested stating the timestamp and url. This is a fairly nice feature for typical use but with requests reaching past 10 requests per second the logs can become a bit excessive. Especially when I am trying scrolling though them all to find some important debug information. It gets even better when the unnecessary logs fill up the history buffer deleting the

Route requests based on the Accept header in Python web frameworks

感情迁移 提交于 2019-12-22 11:29:40
问题 I have some experience with different web frameworks (Django, web.py, Pyramid and CherryPy), and I'm wondering in which one will it be easier and hopefully cleaner to implement a route dispatcher to a different "view/handler" based on the "Accept" header and the HTTP method e.g.: Accept: application/json POST /post/ is handled different than: Accept: text/html POST /post/ So the request gets routed to the particular view of the corresponding handler of the MIME "application/json" and the HTTP

Why don't Django and CherryPy support HTTP verb-based dispatch natively?

半世苍凉 提交于 2019-12-22 03:21:08
问题 It's not the same to POST to an URL than to GET it, DELETE it or PUT it. These actions are fundamentally different. However, Django seems to ignore them in its dispatch mechanism. Basically, one is forced to either ignore HTTP verbs completely or do this on every view: def my_view(request, arg1, arg2): if request.method == 'GET': return get_view(request, arg1, arg2) if request.method == 'POST': return post_view(request, arg1, arg2) return http.HttpResponseNotAllowed(['GET', 'POST']) The few

CherryPy configuration tools.staticdir.root problem

泪湿孤枕 提交于 2019-12-21 22:14:07
问题 How can I make my static-file root directories relative to my application root folder (instead of a hard-coded path)? In accordance with CP instructions (http://www.cherrypy.org/wiki/StaticContent) I have tried the following in my configuration file: tree.cpapp = cherrypy.Application(cpapp.Root()) tools.staticdir.root = cpapp.current_dir but when I run cherrpy.quickstart(rootclass, script_name='/', config=config_file) I get the following error builtins.ValueError: ("Config error in section:

Writing a CherryPy Decorator for Authorization

为君一笑 提交于 2019-12-21 01:18:11
问题 I have a cherrypy application and on some of the views I want to start only allowing certain users to view them, and sending anyone else to an authorization required page. Is there a way I can do this with a custom decorator? I think that would be the most elegant option. Here's a basic example of what I want to do: class MyApp: @authorization_required def view_page1(self,appID): ... do some stuff ... return html def authorization_required(func): #what do I put here? Also can the

cherrypy/jquery CORS trouble

喜夏-厌秋 提交于 2019-12-20 02:28:32
问题 I've got a simple python web server based on cherrypy. Its resources shall provide an API. THe server has the following code to provide CORS: def CORS(): cherrypy.response.headers["Access-Control-Allow-Origin"] = "*" if __name__ == "__main__": cherrypy.tools.CORS = cherrypy.Tool('before_finalize', CORS) cherrypy.quickstart(PyCachedAdmin(), config={'/': {'request.dispatch': cherrypy.dispatch.MethodDispatcher()}}) the server is running on localhost:8080. Now I've got a HTML file, available on

Cherrypy : Do I really need to put it behind a frontend?

我与影子孤独终老i 提交于 2019-12-19 19:44:11
问题 I've been working on a python web app using cherrypy and read it'd be more "robust" to use it as a backend, so I gave it a try. Shortly put, running some benchmarks on a page doing some database operations and serving static & dynamic content has shown that plain cherrypy was twice as fast than nginx and memcached, and about half faster than lighttpd. I heard the latter had memory leak issues, so refrained from using it. And yes, both nginx and lighttpd were configured to serve the static

Multiprocessing works in Ubuntu, doesn't in Windows

∥☆過路亽.° 提交于 2019-12-19 09:08:00
问题 I am trying to use this example as a template for a queuing system on my cherrypy app. I was able to convert it from python 2 to python 3 (change from Queue import Empty into from queue import Empty ) and to execute it in Ubuntu. But when I execute it in Windows I get the following error: F:\workspace\test>python test.py Traceback (most recent call last): File "test.py", line 112, in <module> broker.start() File "C:\Anaconda3\lib\multiprocessing\process.py", line 105, in start self._popen =

CherryPy and concurrency

风格不统一 提交于 2019-12-19 04:22:10
问题 I'm using CherryPy in order to serve a python application through WSGI. I tried benchmarking it, but it seems as if CherryPy can only handle exactly 10 req/sec. No matter what I do. Built a simple app with a 3 second pause, in order to accurately determine what is going on... and I can confirm that the 10 req/sec has nothing to do with the resources used by the python script. __ Any ideas? 回答1: By default, CherryPy's builtin HTTP server will use a thread pool with 10 threads. If you are still

Why are CherryPy object attributes persistent between requests?

孤街醉人 提交于 2019-12-18 17:34:10
问题 I was writing debugging methods for my CherryPy application. The code in question was (very) basically equivalent to this: import cherrypy class Page: def index(self): try: self.body += 'okay' except AttributeError: self.body = 'okay' return self.body index.exposed = True cherrypy.quickstart(Page(), config='root.conf') I was surprised to notice that from request to request, the output of self.body grew. When I visited the page from one client, and then from another concurrently-open client,