cherrypy

Problems serving static files in CherryPy 3.1

谁说胖子不能爱 提交于 2019-12-05 18:37:53
I'm having some trouble serving a static XML stylesheet to accompany some dynamically generated output from a CherryPy web app. Even my test case serving a static text file fails. Static file blah.txt is in the /static directory in my application root directory. In my main site file (conesearch.py contains the CherryPy ConeSearch page-handler class): import conesearch cherrypy.config.update('site.config') cherrypy.tree.mount(conesearch.ConeSearch(), "/ucac3", 'ucac3.config') ... And in site.config I have the following options: [/] tools.staticdir.root: conesearch.current_dir [/static] tools

Route requests based on the Accept header in Python web frameworks

纵然是瞬间 提交于 2019-12-05 18:36:13
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 method "POST". I do know how to implement something like that in CherryPy, but I lose the use of the

Problems serving static files favicon.ico and robots.txt in CherryPy 3.1

坚强是说给别人听的谎言 提交于 2019-12-05 17:28:47
When I try to browse to favicon.ico, for instance, I get this error: ValueError: Static tool requires an absolute filename (got 'favicon.ico') I can get to anything in my /images, /css and /js folders. Those are serving just fine. The site looks and acts great. It's just these darn two files. Here is my root.conf file. [/] tools.staticdir.on = True tools.staticdir.root = "/projects/mysite/root" tools.staticdir.dir = "" [/favicon.ico] tools.staticfile.on = True tools.staticfile.filename = "favicon.ico" tools.staticdir.on = True tools.staticdir.dir = "images" [/robots.txt] tools.staticfile.on =

How to catch all exceptions with CherryPy?

妖精的绣舞 提交于 2019-12-05 09:56:59
I use CherryPy to run a very simple web server. It is intended to process the GET parameters and, if they are correct, do something with them. import cherrypy class MainServer(object): def index(self, **params): # do things with correct parameters if 'a' in params: print params['a'] index.exposed = True cherrypy.quickstart(MainServer()) For example, http://127.0.0.1:8080/abcde: 404 Not Found The path '/abcde' was not found. Traceback (most recent call last): File "C:\Python27\lib\site-packages\cherrypy\_cprequest.py", line 656, in respond response.body = self.handler() File "C:\Python27\lib

Python (CherryPy) web app deployed locally, but not visible over intranet

走远了吗. 提交于 2019-12-05 09:40:31
问题 I've created a Python web app using CherryPy, and have deployed in on my local machine. When I try to view it from another computer in the house, nothing comes back. However, if I create a simple html file, and deploy it with: $ python -m SimpleHTTPServer It is visible over the intranet. I'm stumped as to why my app could work locally, but not be avalable over the intranet, given that there is not a connection problem between these machines, and that I can serve other content on the same port

How to disable SSL3 and weak ciphers with cherrypy builtin ssl module (python 3)

喜欢而已 提交于 2019-12-05 06:10:43
I have configured Cherrypy 3.8.0 with Python 3 to use SSL/TLS. However, I want to disable SSL3 to avoid POODLE. I searched through the documentation but I am unsure on how to implement it. I am using the cherrypy/python builtin ssl module, not pyOpenSSL which I am unable to use under Python 3. Michael Recachinas To disable SSL3, you should set the ssl_context variable yourself rather than accepting the default. Here's an example using Python's built-in ssl module (in lieu of the built-in cherrypy ssl module). import cherrypy import ssl ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23) ctx.options |=

Combining REST dispatcher with the default one in a single CherryPy app

风格不统一 提交于 2019-12-05 03:24:49
问题 I'm trying to make CherryPy to handle request to /api via cherrypy.dispatch.MethodDispatcher() and all other request (like / ) to some default dispatcher. After reading CherryPy's doc I have no idea how to do this. They use both routing methods only separately but this is such a basic thing that I believe it has to work together. #!/usr/local/bin/python2.7 import cherrypy class Root(object): @cherrypy.expose def index(self): return 'Hello world' class RestAPI(object): @cherrypy.expose def

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

守給你的承諾、 提交于 2019-12-05 00:12:55
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 solutions I have found for this in the web ( this snippet for verb-based dispatch, or this decorator for

Streaming POST a large file to CherryPy by Python client

Deadly 提交于 2019-12-04 19:27:15
I'm want to POST a large file from a python client to cherrypy. I'm using the requests library. This is my client code: def upload(fileName=None): url = 'http://localhost:8080/upload' files = {'myFile': ( fileName, open(fileName, 'rb') )} r = requests.post(url, files=files) #with open(fileName,'rb') as payload: #headers = {'content-type': 'multipart/form-data'} #r = requests.post('http://127.0.0.1:8080', data=payload,verify=False,headers=headers) if __name__ == '__main__': upload(sys.argv[1]) The problem is that this puts the whole file in the RAM memory. Is there any way to POST the file in

CherryPy configuration tools.staticdir.root problem

随声附和 提交于 2019-12-04 17:02:29
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: 'global', option: 'tree.cpapp', value: 'cherrypy.Application(cpapp.Root())'. Config values must be