开发者

Ajax Request with Python Tornado Getting a 405

I have some javascript that makes a "POST" call via javascript (no libraries) to a local site running on a diff开发者_如何学编程erent port. If that site is running an app using mod_python, it just works. If it is running an app using Tornado - it fails with a 405 error. I've been sure to implement post() and options() methods on the handler, and it is still erroring out. Since this works with mod_python, this must be possible. Anyone know how to get Tornado to accept requests from the same ip, but a different port? (I'm just doing this locally for testing, and don't care at all about security concerns).


It would help to see both your RequestHandler object, as well as how you dispatch URL's in Tornado. To my knowledge, only missing HTTP method implementations or a missing options() definition would cause tornado to emit a 405.

Maybe the problem isn't that you're not implementing the proper methods, but that the url you're calling isn't being dispatched the way you think it is.

What do the logs say? Are you running tornado in debug mode? While I'm asking questions, what version of tornado are you running?

Try putting tornado in debug mode, and adding some logging.debug messages to insure your request is even making it to your RequestHandler, and to see more of what's going on.

To run in debug mode, with tornado 1.1 (maybe 1.0? Don't recall), you can just start your app with '--logging=debug'. Assuming you have logging.debug calls in your handler, you'll get messages :)

Here's an example handler using the included helloworld.py demo:

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        logging.debug("I'm in ur hndlrz, runnin yr codez")
        self.write("Hello, world")

Here's the log output:

furby:helloworld jonesy$ ./helloworld.py --logging=debug
[D 101207 16:12:34 helloworld:28] I'm in ur hndlrz, runnin yr codez
[I 101207 16:12:34 web:849] 200 GET / (127.0.0.1) 1.03ms
[W 101207 16:12:34 web:849] 404 GET /favicon.ico (127.0.0.1) 0.34ms


Something odd is going on here - but it's not where you think.

The same-origin policy for Ajax actually prevents requests to any different address, even if that address just differs by the port number. See wikipedia's definition of the policy.

So the question actually is, why does it appear as if the mod_python version works? For instance, are you sure that mod_python is listening on the port you think it is? What does the Javascript look like, and how does it determine where it's posting?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜