base.py 文件源码

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

项目:UPPlatform_Python_SDK 作者: Jawbone 项目源码 文件源码
def _request(self, url, method='GET', data=None, ok_statuses=None):
        """
        Issue an HTTP request using the authorized Http object, handle bad responses, set the Meta object from the
        response content, and return the data as JSON.

        :param url: endpoint to send the request
        :param method: HTTP method (e.g. GET, POST, etc.), defaults to GET
        :return: JSON data
        """
        #
        # TODO: clean up the ability to send a POST and add unit tests.
        #
        if data is None:
            req_body = None
        else:
            req_body = urllib.urlencode(data)
        self.resp, self.content = self.http.request(url, method, body=req_body)

        if ok_statuses is None:
            ok_statuses = [httplib.OK]
        self._raise_for_status(ok_statuses)
        resp_json = json.loads(self.content)
        self.meta = upapi.meta.Meta(**resp_json['meta'])
        return resp_json['data']
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号