http.py 文件源码

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

项目:python-karborclient 作者: openstack 项目源码 文件源码
def json_request(self, method, url, **kwargs):
        headers = kwargs.setdefault('headers', {})
        headers['Content-Type'] = kwargs.pop('content_type',
                                             'application/json')
        if 'body' in kwargs:
            if 'data' in kwargs:
                raise ValueError("Can't provide both 'data' and "
                                 "'body' to a request")
            LOG.warning("Use of 'body' is deprecated; use 'data' instead")
            kwargs['data'] = kwargs.pop('body')
        if 'data' in kwargs:
            kwargs['data'] = jsonutils.dumps(kwargs['data'])
            # NOTE(starodubcevna): We need to prove that json field is empty,
            # or it will be modified by keystone adapter.
            kwargs['json'] = None

        resp, body = self.request(url, method, **kwargs)
        if body:
            try:
                body = jsonutils.loads(body)
            except ValueError:
                pass
        return resp, body
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号