rest.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:py-restfmclient 作者: pcdummy 项目源码 文件源码
def _request(self, method, store_path=None, **kwargs):
        with aiohttp.Timeout(self.timeout, loop=self.session.loop):
            url = self.url()
            self.logger.debug('HTTP %s %s' % (method.upper(), url))
            kwargs['headers'] = self.headers
            async with self.session.request(method, url, **kwargs) as response:
                if self.headers['Content-Type'] == 'application/json':
                    result = await response.text()
                    if store_path is not None:
                        await self._store(store_path, method, url, result)

                    if response.status == 404:  # pragma: no cover
                        raise RestNotFoundException("Not found.")

                    try:
                        return json.loads(result)
                    except json.decoder.JSONDecodeError:
                        raise RestDecoderException(result)

                else:  # pragma: no cover
                    return await response.text()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号