result =yieldhttpclient.AsyncHTTPClient().fetch(url)
returnresult
按照一般的方法return会报错
需要使用 raise gen.Return(response.body) 代替return
官方例子
1
2
3
4
@gen.coroutine
deffetch_json(url):
response =yieldAsyncHTTPClient().fetch(url)
raisegen.Return(json_decode(response.body))
In Python 3.3, this exception is no longer necessary: the return statement can be used directly to return a value (previously yield and return with a value could not be combined in the same function).