y***@gmail.com
2018-10-13 18:26:23 UTC
I am struggling with a tornado redirect issue, I am using python 3.6.3,
tornado 5.1.1. Boiling down the code to the minimum to show the problem.
Here is my html file. When it loads it makes a get on the /login end point.
In the /login
end point I am doing a self.redirect() to example.com. See Python code
below the html.
<!DOCTYPE html><html>
<script src="https://d3js.org/d3.v3.js"></script><script>
function login(){
var params = window.location.search;
d3.xhr("http://localhost:8000/login")
.get(function(err, data){
console.log(data);
});
}
</script><body onload="login()"><p id="params"></p></body></html>
The python code is below. When I run it with python3 server.py, the html loads and does GET on the /login and then the browser gives an error:
Failed to load http://example.com/: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access.
What am I doing wrong?
import tornado.ioloop
import tornado.web
import json
import os
R_URL='http://example.com'
class MainHandler(tornado.web.RequestHandler):
def set_default_headers(self):
print("setting headers!!!")
self.set_header("access-control-allow-origin", "*")
self.set_header('Access-Control-Allow-Methods', 'GET, PUT, DELETE, OPTIONS')
self.set_header("Access-Control-Allow-Credentials", "true")
self.set_header("Access-Control-Allow-Headers",
"Authorization, Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, X-Requested-By, If-Modified-Since, X-File-Name, Cache-Control")
def get(self):
print("GET: MainHandler::localhost")
self.redirect(R_URL)
#self.get(R_URL)
def post(self):
print("Received POST")
self.redirect(R_URL)
def make_app():
root = os.path.dirname(__file__)
print("root", root)
application = tornado.web.Application([
(r"/login", MainHandler),
(r"/(.*)", tornado.web.StaticFileHandler, {"path": root, "default_filename": "index.html"}),
])
return application
if __name__ == "__main__":
app = make_app()
app.listen(8000)
print("Listening on port 8000")
tornado.ioloop.IOLoop.current().start()
tornado 5.1.1. Boiling down the code to the minimum to show the problem.
Here is my html file. When it loads it makes a get on the /login end point.
In the /login
end point I am doing a self.redirect() to example.com. See Python code
below the html.
<!DOCTYPE html><html>
<script src="https://d3js.org/d3.v3.js"></script><script>
function login(){
var params = window.location.search;
d3.xhr("http://localhost:8000/login")
.get(function(err, data){
console.log(data);
});
}
</script><body onload="login()"><p id="params"></p></body></html>
The python code is below. When I run it with python3 server.py, the html loads and does GET on the /login and then the browser gives an error:
Failed to load http://example.com/: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access.
What am I doing wrong?
import tornado.ioloop
import tornado.web
import json
import os
R_URL='http://example.com'
class MainHandler(tornado.web.RequestHandler):
def set_default_headers(self):
print("setting headers!!!")
self.set_header("access-control-allow-origin", "*")
self.set_header('Access-Control-Allow-Methods', 'GET, PUT, DELETE, OPTIONS')
self.set_header("Access-Control-Allow-Credentials", "true")
self.set_header("Access-Control-Allow-Headers",
"Authorization, Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, X-Requested-By, If-Modified-Since, X-File-Name, Cache-Control")
def get(self):
print("GET: MainHandler::localhost")
self.redirect(R_URL)
#self.get(R_URL)
def post(self):
print("Received POST")
self.redirect(R_URL)
def make_app():
root = os.path.dirname(__file__)
print("root", root)
application = tornado.web.Application([
(r"/login", MainHandler),
(r"/(.*)", tornado.web.StaticFileHandler, {"path": root, "default_filename": "index.html"}),
])
return application
if __name__ == "__main__":
app = make_app()
app.listen(8000)
print("Listening on port 8000")
tornado.ioloop.IOLoop.current().start()
--
You received this message because you are subscribed to the Google Groups "Tornado Web Server" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-tornado+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Tornado Web Server" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-tornado+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.