cherrypy

Friendly URL for a REST WebService with CherryPy

断了今生、忘了曾经 提交于 2019-12-02 18:44:41
I'm making a RESTful WebService using CherryPy 3 but I encounter a problem : I want to be able to answer requests like : /customers/1/products/386 meaning I want all the product with ID 386 of the client with ID 1. So I try to make it with the CherryPy's MethodDispatcher like this : class UserController(object): exposed = True def __init__(self): self.product = ProductController() @log_io def GET(self, *args): return "GET Users :" + str(args) class ProductController(object): exposed = True @log_io def GET(self, *args): return "GET Product :" + str(args) But when I request /customers/1/products

SSL not working in CherryPy

怎甘沉沦 提交于 2019-12-02 13:08:54
问题 I've seemingly done everything according to docs but SSL just does not work. Here's my CherryPy settings.conf : [global] request.show_tracebacks = False server.socket_port = 443 server.thread_pool = 10 log.screen = True log.error_file = '/root/website/Web.log' log.access_file = '/root/website/Access.log' cherrypy.server.ssl_module = 'pyopenssl' cherrypy.server.ssl_certificate = "/etc/ssl/website/AddTrustExternalCARoot.crt" cherrypy.server.ssl_private_key = "/etc/ssl/website/btcontract_com.key

SSL not working in CherryPy

送分小仙女□ 提交于 2019-12-02 05:12:20
I've seemingly done everything according to docs but SSL just does not work. Here's my CherryPy settings.conf : [global] request.show_tracebacks = False server.socket_port = 443 server.thread_pool = 10 log.screen = True log.error_file = '/root/website/Web.log' log.access_file = '/root/website/Access.log' cherrypy.server.ssl_module = 'pyopenssl' cherrypy.server.ssl_certificate = "/etc/ssl/website/AddTrustExternalCARoot.crt" cherrypy.server.ssl_private_key = "/etc/ssl/website/btcontract_com.key" cherrypy.server.ssl_certificate_chain = "/etc/ssl/website/chain.crt" If I try to load site.com:443 in

Using mappings in CherryPy

北城以北 提交于 2019-12-02 03:41:28
问题 In the "Dispatching / Other Dispatchers" section of the CherryPy documentation, there is an example of Django-style regular-expression-to-view-function mapping definition, but there is no indication on how to attach this to cherrypy.tree . How are you supposed to register this mapping? Edit : Based on the "regex URL mapping" thread in the cherrypy-users Google group, I could figure out that to attach views using regular expressions, you need to use routes-style mapping using the cherrypy

“no 'Access-Control-Allow-Origin' header is present” error with Cherrypy

做~自己de王妃 提交于 2019-12-01 20:53:43
问题 I have the following javascript in a HTML page <script> function getContent(page) { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { var json = xmlhttp.responseText; obj = JSON.parse(json); document.getElementById("content").innerHTML=obj.content;

cherrypy/jquery CORS trouble

烈酒焚心 提交于 2019-12-01 20:45:41
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 localhost (default port 80) which loads jquery 1.9. I open the browser console to try the $.ajax to

CherryPy Custom Tool for user authentication

戏子无情 提交于 2019-12-01 19:38:20
I'm trying to set up a simple way of decorating methods in my CherryPy controller classes so that a user is redirected to the login page if they haven't authenticated yet. I was going to do a basic Python decorator, but an answer here suggested I use a CherryPy Custom Tool instead. So I'm trying to do that, but I can't get it to work. Here's what I have: def authenticate(): user = cherrypy.session.get('user', None) if not user: raise cherrypy.HTTPRedirect('/?errMsg=Please%20log%20in%20first') cherrypy.tools.authenticate = cherrypy.Tool('on_start_resource', authenticate) The /home page is a

“no 'Access-Control-Allow-Origin' header is present” error with Cherrypy

﹥>﹥吖頭↗ 提交于 2019-12-01 18:58:29
I have the following javascript in a HTML page <script> function getContent(page) { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { var json = xmlhttp.responseText; obj = JSON.parse(json); document.getElementById("content").innerHTML=obj.content; document.getElementById("title").innerHTML=obj.title; } } xmlhttp.open("GET","http://differentserver.com:8080

Uploading a file in ajax to CherryPy

大兔子大兔子 提交于 2019-12-01 13:39:23
I am trying to upload many files at once to my CherryPy server. I am following this tutorial that shows PHP code on the server side. The JavaScript part is simple. Here is a summary of what it does: function FileSelectHandler(e) { var files = e.target.files || e.dataTransfer.files; for (var i = 0, f; f = files[i]; i++) { var xhr = new XMLHttpRequest(); xhr.open("POST", "upload", true); xhr.setRequestHeader("X_FILENAME", file.name); xhr.send(file); } I translated the upload.php described in the tutorial into something like this: def upload(self): [...] When the server receives the request I can

How to stop request processing in Cherrypy?

时光总嘲笑我的痴心妄想 提交于 2019-12-01 11:44:25
im using python 2.6, cherrypy 3.1 i have some problem with timeout of the requests. I simply need to be requests done in Limit (30 seconds). after that limit, the processes should be killed and answer returned server is starting through tree.mount(); cherrypy.start(); cherrypy.block() as first thing... when i try to kill app (by Ctrl+C (debian 6.0)), app is stuck on: Waiting for child threads to terminate... how to kill the processes on exit and how to handle the timeout connection for killin the process which is not responding? I cant write here any code, because it is strictly proprietary,