tornado

tornado加载CSS后无效果

十年热恋 提交于 2019-12-05 22:11:52
用tornado做了一个简单的页面。结果页面中的css被加载了,但是没有效果。用谷歌浏览器调试,说是Resource interpreted as Stylesheet but transferred with MIME type application/x-css。大概意思就是css文件被识别为样式表了,但是传输的时候是以application/x-css格式。这样就造成浏览器不能正常显示页面,css完全不起作用。原因就是,tornadod中的web.py在设置content_type时会调用 mimetypes.guess_type() 而mimetypes在初始化的时候,如果是windows环境下,就会读取本地的注册表。 因此只要把注册表中,css文件的Content Type由applicntion/x-css 改为text/css即可。 来源: https://my.oschina.net/u/3021599/blog/3134712

Why is “pip install tornado” not installing the tornado module?

一曲冷凌霜 提交于 2019-12-05 22:01:19
I am trying to install tornado onto my virtual environment, so I can get Jupyter to work. I tried pip install tornado and it seems like it runs but it only installs other modules. I even tried to uninstall tornado and then try to reinstall it, but since it doesn't exist, I can't even uninstall it. Is there a way to install tornado so I can see it? I feel like I've tried everything. Any advice? Edit1: I should mention, updating pip did nothing. The shell output below is me setting up virtual environment and activating it [ec2-user@ip-172-31-51-121 ~]$ virtualenv venv New python executable in

Any suggestion for using non-blocking MySQL api on Tornado in Python3?

筅森魡賤 提交于 2019-12-05 21:22:33
i was hoping tornado support for asynchronous sql database opertion ,after i read the source code, http://www.tornadoweb.org/documentation/_modules/tornado/database.html#Connection sigh,they are blocking version.here's some choice . Plan A: find a set of api similar to mysqldb module except they use callback to return the reuslt.sorry i didn't find one that show examples that's their api can handle non-blocking mysql operation Plan B: use the block version .i heard the writer of tornado suggest developers use block version,and extremely optimize your sql query for shorten the blocking period.

How would I implement “tail” over HTTP with Python Tornado?

冷暖自知 提交于 2019-12-05 21:09:06
I'm trying to implement something like "tail -f" over HTTP with Python. Currently, I'm trying to use Tornado, but it only is handling one connection at a time, even when I do asynchronous requests. import socket import subprocess import tornado.gen as gen import tornado.httpserver import tornado.ioloop import tornado.iostream import tornado.options import tornado.web from tornado.options import define, options define("port", default=8888, help="run on the given port", type=int) define( "inputfile", default="test.txt", help="the path to the file which we will 'tail'", type=str) class

How can Tornado serve a single static file at an arbitrary location?

狂风中的少年 提交于 2019-12-05 19:32:33
问题 I am developing a simple web app with Tornado. It serves some dynamic files and some static ones. The dynamic ones are not a problem, but I am having trouble serving a static file. What I am looking to do is to serve the file /path/to/foo.json when the /foo.json URL is accessed. Note that /path/to/foo.json is outside the document root. In Apache I would just set up an Alias. With Tornado I have: app = tornado.web.Application([ (r'/dynamic\.html', MyService, dict(param = 12345)), (r'/(foo\

Tornado celery can't use gen.Task or CallBack

回眸只為那壹抹淺笑 提交于 2019-12-05 19:04:35
class AsyncHandler(tornado.web.RequestHandler): @tornado.web.asynchronous def get(self): tasks.sleep.apply_async(args=[5], callback=self.on_result) def on_result(self, response): self.write(str(response.result)) self.finish() raise error : raise TypeError(repr(o) + " is not JSON serializable") TypeError: <bound method AsyncHandler.on_result of <__main__.AsyncHandler object at 0x10e7a19d0>> is not JSON serializable The broker and backends all use redis, I just copied from https://github.com/mher/tornado-celery When I use amqp broker and redis backends it works well, but not when using the redis

How to run the Tornado event loop alongside a Kivy GUI?

烂漫一生 提交于 2019-12-05 18:59:10
My client application uses a Kivy GUI (Kivy has its own event loop) and connects to the server using the WebSocket protocol with Tornado (Tornado also has an event loop). That's why the connection part is asynchronous. I want the user to interact with the UI while a Tornado client is running an infinite asynchronous loop of listening for server messages. Here's some example code: client_test.py from tornado.ioloop import IOLoop from tornado.websocket import websocket_connect class RequestSender: url = 'server url here (no scheme)' async def _connect(self): self.conn = await websocket_connect(

Tornado Web & Persistent Connections

送分小仙女□ 提交于 2019-12-05 15:07:22
How can I write Http server in TornadoWeb that will support persistent Connections. I mean will be able to receive many requests and answer to them without closing connection. How does it actually work in async? I just want to know how to write handler to handle persistent connection. How actually would it work? I have handler like that: class MainHandler(RequestHandler): count = 0 @asynchronous def post(self): #get header content type content_type = self.request.headers.get('Content-Type') if not content_type in ACCEPTED_CONTENT: raise HTTPError(403, 'Incorrect content type') text = self

tornado表单和模板

人走茶凉 提交于 2019-12-05 12:00:59
模板渲染,指定模板路径: app = tornado.web.Application( handlers=[(r'/my', Myrequest),('/myweb',MywebRequest)], template_path=os.path.join(os.path.dirname(__name__),'templates')) 向Application对象的__init__方法传递了一个template_path参数。 template_path=os.path.join(os.path.dirname(__file__), "templates") template_path参数告诉Tornado在哪里寻找模板文件 self.render('index.html',params=params)这段代码告诉Tornado在templates文件夹下找到一个名为index.html的文件,读取其中的内容,并且发送给浏览器。 params是传递给前端页面的变量,模板用{{ params }}填充 模板标签{% if %},{% for %},以{% end %}结束 {% for key in d %} <li>{{key}}</li> {% end %} {% if uname %} <h1>you name</h1> {% else %} <h1>wu name</h1> {%

i春秋CTF-“百度杯”CTF比赛 九月场 XSS平台

人走茶凉 提交于 2019-12-05 11:42:28
“百度杯“CTF比赛 九月场 ###XSS平台 看了别人的wp才知道这里需要变数组引起报错然后百度信息收集,这一步在实战中我觉得是很有作用的,get到。 这里取百度rtiny,看别人wp上说这里是因为前面的目录很正常,这个rtiny看起来有问题,就去百度。。 百度第一栏直接拿下源码,接下来就是代码审计。这几天做题老是遇到pythonweb框架的服务器,所以直接去康啦康教程 这里直接推荐一篇文章 http://shouce.jb51.net/tornado/ 代码审计 这里因为之前就看了别人的wp 所以我知道问题出现在lock.py里面哈哈哈 Username 和passwd都没坐什么过滤 直接带入数据库查询 这是定义的ct 组合起来语句就是 Select * from manager where username='' and password='' Username来自cookie 但是cookie被加密过 Tornado的 set_secure_cookie() 和 get_secure_cookie() 函数发送和取得浏览器的cookies,以防范浏览器中的恶意修改。为了使用这些函数,你必须在应用的构造函数中指定 cookie_secret 参数。 Tornado将cookie值编码为Base-64字符串,并添加了一个时间戳和一个cookie内容的HMAC签名