def fetch(self, url: str, encoding: str = 'utf-8') -> HTTPResponse:
"""Fetch url and return ``tornado.httpclient.HTTPResponse`` object.
Response body is decoded by ``encoding`` and set ``text`` property of
the response. If failed to decode, ``text`` property will be ``None``.
"""
response = await to_asyncio_future(
AsyncHTTPClient().fetch(url, raise_error=False))
if response.body:
try:
response.text = response.body.decode(encoding)
except UnicodeDecodeError:
response.text = None
else:
response.text = None
return response
评论列表
文章目录