quip.py 文件源码

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

项目:slack-invite-flow 作者: mena-devs 项目源码 文件源码
def get_blob(self, thread_id, blob_id):
        """Returns a file-like object with the contents of the given blob from
        the given thread.

        The object is described in detail here:
        https://docs.python.org/2/library/urllib2.html#urllib2.urlopen
        """
        request = urllib2.Request(
            url=self._url("blob/%s/%s" % (thread_id, blob_id)))
        if self.access_token:
            request.add_header("Authorization", "Bearer " + self.access_token)
        try:
            return urllib2.urlopen(request, timeout=self.request_timeout)
        except urllib2.HTTPError, error:
            try:
                # Extract the developer-friendly error message from the response
                message = json.loads(error.read())["error_description"]
            except Exception:
                raise error
            if (self.retry_rate_limit and error.code == 503 and
                message == "Over Rate Limit"):
                # Retry later.
                reset_time = float(error.headers.get("X-RateLimit-Reset"))
                delay = max(2, reset_time - time.time() + 1)
                logging.warning("Rate Limit, delaying for %d seconds" % delay)
                time.sleep(delay)
                return self.get_blob(thread_id, blob_id)
            else:
                raise QuipError(error.code, message, error)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号