cherrypy

Path Not Found in CherryPy

风流意气都作罢 提交于 2019-12-11 17:57:58
问题 I've been working on implementing a test API in CherryPy. I've read a few forums, tutorials and pieced together the code that the old Python developer at work had written and this is what I've got: import json import cherrypy class person: def default(self, *args): r = { 'firstName': args[0], 'lastName': args[1], 'age': args[2] } return json.dumps(r) default.exposed = True class api: def __init__(self): self.person = person() class Root: def __init__(self): self.api = api() conf = { '/': {

Cherrypy and Parsing XML Data from multiple files

那年仲夏 提交于 2019-12-11 15:23:35
问题 So this is sort of a piggy-back post of another question I had. I've successfully pulled data from multiple xml files and am able to get the data to display within the terminal using the print function, but when I try to use the return function to show the data in the browser, I only get the data from the first file. Any ideas on why I only get data from the first file rather than all of them? Thanks! from xml.dom.minidom import parse, parseString import os, glob, re import cherrypy class

cherrypy.session won't work on Chrome but works on Firefox

坚强是说给别人听的谎言 提交于 2019-12-11 14:26:47
问题 I run a web with CherryPy (version 3.2.0) and use cherrypy.session to store session specific data. It works perfectly with Firefox. However, I noticed that cherrypy.session would run in problems on Chrome. Basically, it looks like session variable resets when the consequent pages are being browsed. I believe my config is set correctly tools.sessions.on = True tools.sessions.storage_type = "ram" tools.sessions.storage_path = "/home/dmitry/test/sessions" tools.sessions.timeout = 60 tools

how to use multiple dispatchers in same cherrypy application?

让人想犯罪 __ 提交于 2019-12-11 13:33:48
问题 I have a cherrypy application like this: import cherrypy from controllers import UsersController class Root(object): exposed = True def index(self): return 'welcome' if __name__ == '__main__': root = Root() root.users = UsersController() cherrypy.tree.mount( root, '/', { '/users' : {'request.dispatch' : cherrypy.dispatch.MethodDispatcher()} } ) cherrypy.engine.start() cherrypy.engine.block() Now I wish to use MethodDispatcher() for providing REST api to /users resource and I want a default

How to send a javascript array to cherrypy

爱⌒轻易说出口 提交于 2019-12-11 12:48:23
问题 I have a jQuery post something like var arr = ['some', 'string', 'array']; jQuery.post('saveTheValues', { 'values': arr }, function(data) { //do stuff with the returned data }, 'json' ); And it goes to a cheerypy function: @cherrypy.expose def saveTheValues(self, values=None): #code to save the values But running the javascript returns 400 Bad Request because Unexpected body parameters: values[] . How can I send an array to cherrypy? 回答1: The problem is that newer jQuery versions send the

cherrypy as a gevent-socketio server

霸气de小男生 提交于 2019-12-11 11:37:30
问题 I have just started using gevent-socketio and it's great! But I have been using the default socketioserver and socketio_manage from the chat tutorial and was wondering how to integrate socketio with cherrypy . essentially, how do I turn this: class MyNamespace(BaseNamespace):... def application(environ, start_response): if environ['PATH_INFO'].startswith('/socket.io'): return socketio_manage(environ, { '/app': MyNamespace}) else: return serve_file(environ, start_response) def serve_file(...):

Pass JavaScript array to cherrypy with AJAX

三世轮回 提交于 2019-12-11 10:57:22
问题 I'm trying to send an array to cherrypy but it turns out empty. This is my js file. I've checked and the array gets filled as it should. $(function () { $('#mark-read').on('click', function (e) { alert_ids = []; $("input:checkbox[name=alert-cb]:checked").each(function() { alert_ids.push($(this).attr('id')); }); $.ajax({ type: 'POST', url: 'markasread', data: { alerts: alert_ids }, traditional: true, success: function (data) { alert(data); } }); }); }); This is the cherrypy part (I used this

Strange behavior with multiple ajax requests to the same URL

自作多情 提交于 2019-12-11 10:19:04
问题 I constructed a strange situation in a CherryPy server, and I'd like some help understanding exactly what's happening, and why. Here is server.py : import cherrypy import os import threading class Root(object): def __init__(self): self.count = 0; self.lock = threading.Lock() @cherrypy.expose def app(self): with self.lock: self.count += 1 return "Call #%d" % (self.count) if __name__ == '__main__': cherrypy.quickstart(Root(), "/", {"/": { "tools.staticdir.on": True, "tools.staticdir.dir": os

Error using session RamSession with cherrypy behind nginx

為{幸葍}努か 提交于 2019-12-11 06:28:06
问题 I am running a cherrypy application using my own session based of RamSession behind nginx. The problem is the session id changes on every request. I believe the problem is every time a request is made it goes to a different worker and thus the session is saved, but it is not recognized in the next request by the next available worker (limited knowledge on how things work unfortunately). When I set the number of workers to 1 then everything works as expected. I know I can probably use

Post JSON using Python Requests

坚强是说给别人听的谎言 提交于 2019-12-11 02:38:25
问题 I need to POST a JSON from a client to a server. I'm using Python 2.7.1 and simplejson. The client is using Requests. The server is CherryPy. I can GET a hard-coded JSON from the server (code not shown), but when I try to POST a JSON to the server, I get "400 Bad Request". Here is my client code: data = {'sender': 'Alice', 'receiver': 'Bob', 'message': 'We did it!'} data_json = simplejson.dumps(data) payload = {'json_payload': data_json} r = requests.post("http://localhost:8080", data=payload