- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下代码会不断触发ERROR:tornado.application:Uncaught exception GET
,但似乎无法弄清楚如何正确处理它?
class MainHandler(tornado.web.RequestHandler):
@tornado.gen.coroutine
def get(self, id):
http = tornado.httpclient.AsyncHTTPClient()
endpoint = "https://www.foobar.com/api/v1"
foo = yield http.fetch("{}/foo/{}".format(endpoint, id), self._handle_fetch)
bar = yield http.fetch("{}/bar/{}".format("http://www.doh.com", id), self._handle_fetch)
// do other things at this point like serve content to user
def _handle_fetch(self, response):
if response.error:
print("there was an error so returning None")
return {}
else:
print("everything OK so returning response")
return response
try:
foo = yield http.fetch("{}/foo/{}".format(endpoint, id), self._handle_fetch)
bar = yield http.fetch("{}/bar/{}".format("http://www.doh.com", id), self._handle_fetch)
print(foo.body)
print(bar.body)
except tornado.httpclient.HTTPError as e:
print("Error: " + str(e))
except Exception as e:
print("Error: " + str(e))
fetch
,因为如果
foo
成功并且
bar fails. But if
foo`失败,我仍然想尝试并继续提供内容我想使整个响应失败并发送自定义错误
最佳答案
好的,我设法解决了这个问题:
import tornado.ioloop
import tornado.web
import tornado.httpclient
import html2text
import json
class MainHandler(tornado.web.RequestHandler):
@tornado.gen.coroutine
def get(self, id):
http = tornado.httpclient.AsyncHTTPClient()
endpoint = "https://www.foo.com/api/v1"
try:
foo = yield http.fetch("{}/foo/{}".format(endpoint, id))
bar = yield http.fetch("{}/bar/{}".format("http://www.doh.com", id))
except tornado.httpclient.HTTPError as e:
if "bar" in e.response.effective_url:
bar = "change bar value"
else:
foo = "change foo value"
self._response(foo, bar)
def _response(self, foodict, bardict):
self.write("...")
self.finish()
if __name__ == "__main__":
application = tornado.web.Application([
(r"/api/v1/foobar/(\d{7})/?", MainHandler),
])
application.listen(8888)
tornado.httpclient.AsyncHTTPClient.configure("tornado.simple_httpclient.SimpleAsyncHTTPClient", max_clients=2, defaults=dict(connect_timeout=float(10), request_timeout=float(100)))
tornado.ioloop.IOLoop.current().start()
关于python - 如何处理Python错误:tornado.application:Uncaught exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36908662/
根据一些谷歌搜索,我安装了以下错误处理程序。然而,似乎返回 http 500 的 python 异常并没有被这些东西捕获,尽管 404 是这样。通过我在下面的代码中留下的打印语句,我可以看到它没有命中
我刚刚意识到 WebSocketHandler.write_message() 返回一个 Future。我以前没有在我的函数中产生过这个函数: @tornado.gen.coroutine
这是我的 Tornado 文件:: from tornado.wsgi import WSGIContainer from tornado.ioloop import IOLoop from torn
class MainHandler(BaseHandler): @tornado.web.authenticated def get(self): self.rende
我正在尝试使用 AsyncHTTPTestCase 测试 Tornado .我想测试标有 @tornado.web.authenticated 注释的处理程序。因为此处理程序需要身份验证,所以我们必须
我正在使用 Tornado Web Server (版本 4.1)使用 Python 2.7 创建 REST Web 应用程序。我的请求处理程序之一 (web.RequestHandler) 使用多部
我想知道tornado 的内部工作流程,并且看过this article ,很好,但我就是想不通 ioloop.py里面有这样一个函数 def add_handler(self, fd, handle
如何遍历从 Python/Tornado 处理程序传递到 Tornado 模板的字典? 我试过 {% for key, value in statistics %}
我有一个 Tornado 后端,为 Angular 前端提供服务。更新数据库时,tornado api 不会获取更新的数据。它仅在我重新启动服务器后出现。有人可以帮我解决这个问题吗?我希望获取的数据能
我尝试使用自定义的 WSGIContainer 来处理异步操作: from tornado import httpserver, httpclient, ioloop, wsgi, gen @gen.
from tornado.web import RequestHandler class HelloWorldHandler(RequestHandler): def get(self):
Pylint 遇到 @tornado.web.authenticated 时崩溃 class Handler1(tornado.web.RequestHandler): def get(sel
经过 tornado.gen documentation有人可以帮我理解 tornado.gen.coroutine 和 tornado.gen.engine 之间的确切区别 最佳答案 正如 gen.
代码如下: from tornadoredis import Client from tornado.ioloop import IOLoop from tornado.gen import coro
我有一个 tornado.websocket.WebSocketHandler 的子类。在该类中,我有一个方法使用 Django ORM 从子类模型中获取用户:django.contrib.auth.
我是 ssl 之类的新手,我已经使用 openssl 生成了自签名证书。 openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days
我已经从 tornado 4.2 移动到 tornado 6.0.3,我得到了错误 AttributeError:模块“tornado.web”没有属性“异步” 根据 tornado v6 seems
我一直在关注此 ( https://developer.ibm.com/tutorials/se-distributed-apps-zeromq-part2/) 教程,以设置使用 CurveZMQ 加
我在使用tornado-celery整合tornado和celery时,出现错误:``` traceback (most recent call last): File "/usr/local/l
我正在使用 Tornado 与 twitter 等第三方进行身份验证。 我的登录处理程序看起来像这样 class AuthLoginHandler(BaseHandler, tornado.auth.
我是一名优秀的程序员,十分优秀!