Example #1
0
 def post(self):
     '''
         {
         status=,
         rid=,
         zone_name=,
         }
     '''
     rid = int()
     domain_name = str()
     record_status = str()
     try:
         rid = self.get_argument('rid')
         domain_name = self.get_argument('zone_name')
         record_status = 'enable' if 'True' in self.get_argument('status') else 'disable'
     except:
         raise HTTPError('params is error!!')
     func = yield self.initRequest()
     domain_id = yield Task(self._Domainid, func, domain_name)
     request = yield func.urlPost(self.dnspod_api['record']['disable'], domain_id=domain_id, record_id=rid, status=record_status)
     print request[0]
     print request[1]
     if request[0]:
         self.write(convJson(request[1]))
     else:
         raise HTTPError(request[1])
Example #2
0
    async def fetch_with_retry(tries, logger, url, http_client, kwargs):
        kwargs['raise_error'] = False

        # this makes it possible to override the default
        # retry_timeout
        retry_timeout = kwargs.get('retry_timeout', 0.5)

        if 'retry_timeout' in kwargs:
            del kwargs['retry_timeout']

        attempts = 0
        last_exception = None
        while attempts < tries:
            attempts = attempts + 1
            try:
                res = await http_client.fetch(url, **kwargs)
                if res.code == 599:  # Network connectivity issues.
                    raise HTTPError(res.code,
                                    message=str(res.error),
                                    response=res)
                return res
            except HTTPError as e:
                last_exception = e
                logger.error(
                    f'Failed to call {url}; attempt={attempts}; err={str(e)}')
                await asyncio.sleep(retry_timeout)

        assert last_exception is not None  # Impossible.
        raise HTTPError(500, message=f'Failed to call {url}!') \
            from last_exception
Example #3
0
    def get(self):
        """
        Handle to get lists of contests
        """

        try:
            session = self.acquire_sql_session()
        except:
            raise HTTPError(500, 'Could not acquire database connection')

        try:
            contests_running = ContestRepository.get_active_contests(session)
            contests_upcoming = ContestRepository.get_future_contests(session)
            contests_recent = ContestRepository.get_recent_contests(session)
        except:
            raise HTTPError(500, 'A database error has occured.')

        session.close()

        self.render("contest_list.html",
                    contests_running=contests_running,
                    contests_upcoming=contests_upcoming,
                    contests_recent=contests_recent,
                    dateOf=dateOf,
                    timeOf=timeOf)
Example #4
0
    def delete(self, id):

        userid = self.current_user['nid']
        cursor = self.conn.cursor()
        try:
            cursor.execute(
                "select nid, ncreate_at, nuser_id, dtotal, nhandlered \
                from tborders where nid={0}".format(id))
        except:
            raise HTTPError(500)
        if cursor.rowcount > 0:
            orderinfo = cursor.fetchone()
            if orderinfo[4] == 1:  # already handler
                raise HTTPError(400, 'bad request')
            else:
                if userid != orderinfo[2]:
                    raise HTTPError(403)
                else:
                    try:
                        cursor.execute(
                            "delete from tborders where nid={0}".format(id))
                    except:
                        raise HTTPError(500)
                    self.conn.commit()
                    cursor.close()

        return
Example #5
0
    def test_no_retry_codes(self):
        request, valid_response = create_valid_ack()
        ok_error = HTTPError(405)
        self.mock_client.side_effect = [HTTPError(404), ok_error]

        found_response = http.send_request(request, 3, no_retry_codes=[405])
        self.assertEqual(found_response.error, ok_error)
        self.assertEqual(self.mock_client.call_count, 2)
Example #6
0
 def test_handle_response(self):
     """проверяем, что ошибки обрабатываются должным образом"""
     r = Index.handle_errors(HTTPError(httplib.INTERNAL_SERVER_ERROR))
     self.assertDictEqual(
         r, dict(status=STATUSES['error'], error=ERRORS['decode']))
     r = Index.handle_errors(HTTPError(httplib.SEE_OTHER))
     self.assertDictEqual(
         r, dict(status=STATUSES['error'], error=ERRORS['timeout']))
Example #7
0
 def wrapper(self, *args, **kwargs):
     ''' now that, this function need admin role, login error alse raise 403
     
     if not self.current_user or self.current_user.get('nrole') == 0:
         raise HTTPError(403)
     '''
     if not self.current_user:
         raise HTTPError(401)
     if self.current_user.get('nrole') == 0:
         raise HTTPError(403)
     return method(self, *args, **kwargs)
Example #8
0
 def check_xsrf_cookie(self):
     token = (
             self.get_cookie("_xsrf", None)
             or self.request.headers.get("X-Xsrftoken")
             or self.request.headers.get("X-Csrftoken")
     )
     if not token:
         raise HTTPError(403, "'_xsrf' cookie missing from POST")
     _, token, _ = self._decode_xsrf_token(token)
     _, expected_token, _ = self._get_raw_xsrf_token()
     if not token:
         raise HTTPError(403, "'_xsrf' cookie has invalid format")
     if not hmac.compare_digest(utf8(token), utf8(expected_token)):
         raise HTTPError(403, "XSRF cookie does not match POST argument")
Example #9
0
 async def get(self):
     unverified_base64_token = self.get_argument('token')
     unverified_token = base64.urlsafe_b64decode(unverified_base64_token)
     try:
         token = jwt.decode(unverified_token, public_key, algorithms='RS256')
     except jwt.exceptions.ExpiredSignatureError:
         raise HTTPError(
             403, "Sharing link has expired. Ask for a fresh link."
         )
     except jwt.exceptions.InvalidSignatureError:
         raise HTTPError(
             403, ("Sharing link has an invalid signature. Was it "
                   "copy/pasted in full?")
         )
     self.write({'token': token})
Example #10
0
def stop_app_instance(version_key, port):
    """ Stops a Google App Engine application process instance on current
      machine.

  Args:
    version_key: A string, the name of version to stop.
    port: The port the application is running on.
  Returns:
    True on success, False otherwise.
  """
    project_id = version_key.split(VERSION_PATH_SEPARATOR)[0]

    if not misc.is_app_name_valid(project_id):
        raise BadConfigurationException(
            'Invalid project ID: {}'.format(project_id))

    logging.info('Stopping {}:{}'.format(version_key, port))

    # Discover revision key from version and port.
    instance_key_re = re.compile('{}{}.*-{}'.format(MONIT_INSTANCE_PREFIX,
                                                    version_key, port))
    monit_entries = yield monit_operator.get_entries()
    try:
        watch = next(entry for entry in monit_entries
                     if instance_key_re.match(entry))
    except StopIteration:
        message = 'No entries exist for {}:{}'.format(version_key, port)
        raise HTTPError(HTTPCodes.INTERNAL_ERROR, message=message)

    yield unmonitor_and_terminate(watch)

    yield monit_operator.reload()
    yield clean_old_sources()
Example #11
0
    async def execute_downstream(self) -> HTTPResponse:
        """
        Executes the downstream request (Jupyter to AWS service) and return the response or the error
        after adding SigV4 authentication.

        "allow_nonstandard_methods" is used because Tornado rejects POST requests without a body without this parameter,
        and some operations send such requests (such as S3.InitiateMultipartUpload)
        :return: the HTTPResponse
        """
        if (self.whitelisted_services is not None
                and self.service_info.service_name
                not in self.whitelisted_services):
            raise HTTPError(
                403,
                message=
                f"Service {self.service_info.service_name} is not whitelisted for proxying requests",
            )

        base_service_url = urlparse(self.service_info.endpoint_url)
        start_index = self.upstream_request.path.index("/awsproxy") + len(
            "/awsproxy")
        downstream_request_path = (base_service_url.path +
                                   self.upstream_request.path[start_index:]
                                   or "/")
        return await AsyncHTTPClient().fetch(
            HTTPRequest(
                method=self.upstream_request.method,
                url=self._compute_downstream_url(downstream_request_path),
                headers=self._compute_downstream_headers(
                    downstream_request_path),
                body=self.upstream_request.body or None,
                follow_redirects=False,
                allow_nonstandard_methods=True,
            ))
Example #12
0
    def test_get_repository_no_parent(self):
        service = Service(id="serv1",
                          type="service",
                          name="service",
                          organisation_id="org2",
                          location="https://example.com")

        with patch.object(Repository,
                          "get_parent",
                          side_effect=couch.NotFound(
                              HTTPError(404, 'Not Found'))):
            with patch.object(
                    Service, "get",
                    return_value=make_future(service)) as get_service:
                repo = Repository(**self.REPOSITORY)
                user = User(**self.USER)
                result = yield repo.with_relations(user)

                get_service.assert_called_with('serv1')

                assert result == {
                    "organisation": {
                        "id": "org1"
                    },
                    "name": "repository",
                    "created_by": "user1",
                    "state": "approved",
                    "service": {
                        "id": "serv1",
                        "name": "service",
                        "organisation_id": "org2",
                        "location": "https://example.com"
                    },
                    "id": "repo1"
                }
Example #13
0
 def get(self):
     userid = self.current_user['nid']
     cursor = self.conn.cursor()
     try:
         cursor.execute(
             "select nid, dcreate_at, nuser_id, dtotal, nhandlered \
             from tborders where nuser_id={0}".format(userid))
     except:
         raise HTTPError(500)
     if cursor.rowcount > 0:
         orders = cursor.fetchall()
         orders_json = [{
             'nid': order[0],
             'dcreate_at': time.mktime(order[1].timetuple()),
             'nuser_id': order[2],
             'dtotal': order[3],
             'nhandlered': order[4]
         } for order in orders]
         # return self.write(json_encode({
         #   'orders':orders_json
         #   }))
         return self.write(json.dumps(orders_json))
     else:
         # self.set_status(404)
         # return self.write(json_encode({
         #   'orders':None
         #   }))
         return self.write(json.dumps([]))
Example #14
0
    def get(self):
        '''
        get favorite goods, return goods list
        '''
        # return self.write("hello world:{0}".format(self.current_user.get("nid")))
        userid = self.current_user['nid']
        cursor = self.conn.cursor()
        try:
            cursor.execute(
                "select a.nid, a.cname, a.dprice, a.cdesc, a.ncategoryid, a.ncount \
                            from tbgoods as a, tbfavorites as b \
                            where a.nid=b.ngood_id and b.nuser_id={0}".format(
                    userid))
        except:
            raise HTTPError(500)

        if cursor.rowcount > 0:
            goods = cursor.fetchall()
            cursor.close()
            goods_json = [{
                "nid": good[0],
                "cname": good[1],
                "dprice": good[2],
                "cdesc": good[3],
                "ncategoryid": good[4],
                "ncount": good[5]
            } for good in goods]
            return self.write(json.dumps(goods_json))
        else:
            return self.write(json.dumps([]))
Example #15
0
    def fetch(self, url, *args, **kwargs):
        base_url = url.split("?")[0]

        if base_url not in self.mocked_urls:
            response = yield self.original_fetch(url, *args, **kwargs)
            raise gen.Return(response)

        responses = self.mocked_urls[base_url]

        if len(responses) == 0:
            raise MissingMockResponse(
                "URL requested too many times: {}".format(base_url))

        expected_method, response = responses.pop(0)
        request_method = kwargs.get("method", "GET")

        if expected_method != request_method:
            responses.insert(0, (expected_method, response))
            response = MockResponse(url)
            response.body = \
                "Method mismatch ({}) for mocked URL: {} {}".format(
                    request_method, expected_method, base_url)
            response.code = 405

        if response.code > 399 and kwargs.get("raise_error", True):
            raise HTTPError(code=response.code,
                            message="Mock error: ({}) {}".format(
                                response.code, response.body),
                            response=response)
        raise gen.Return(response)
Example #16
0
    def get_current_user(self):
        auth_header = self.request.headers.get('Authorization')

        if auth_header is None or not auth_header.startswith('Basic '):
            return None
        auth_decoded = base64.decodestring(auth_header[6:])
        email, password = auth_decoded.split(':', 2)
        cursor = self.conn.cursor()
        try:
            cursor.execute("select nid, cemail, cname, nrole from tbusers \
                where cemail='{0}' and cpassword='******'".format(
                email, password))
        except:
            raise HTTPError(500, "db error")
        if cursor.rowcount > 0:
            userinfo = cursor.fetchone()
            cursor.close()
            return {
                "nid": userinfo[0],
                "cemail": userinfo[1],
                "cname": userinfo[2],
                "nrole": userinfo[3]
            }
        else:
            return None
 def _on_timeout(self):
     self._timeout = None
     if self.callback is not None:
         self.callback(HTTPResponse(self.request, 599,
                                    error=HTTPError(599, "Timeout")))
         self.callback = None
     self.stream.close()
Example #18
0
    def handle_exception(self, typ, error, tb):
        if isinstance(error, _RequestTimeout):
            if self._stream_ended:
                self.finish()
                return True
            else:
                error = HTTPError(599, "Timeout")

        self._remove_timeout()
        self._unregister_unfinished_streams()
        if hasattr(self, 'stream_id'):
            self.context.remove_stream_delegate(self.stream_id)

            # FIXME: our nginx server will simply reset stream,
            # without increase the window size which consumed by
            # queued data frame which was belongs to the stream we're resetting
            # self.context.reset_stream(self.stream_id, flush=True)
            self.context.reset_stream_ids.append(self.stream_id)

        error.__traceback__ = tb
        response = HTTP2Response(
            self.request,
            599,
            error=error,
            request_time=self.io_loop.time() - self.start_time,
        )
        self._run_callback(response)
        return True
 def content_type(self):
     """
     Returns the content type of the client's request
     
     See:
         
         http://www.w3.org/Protocols/rfc2616/rfc2616-sec12.html
         
         http://www.ietf.org/rfc/rfc2295.txt
         
         http://httpd.apache.org/docs/2.2/content-negotiation.html
         
         http://www.w3.org/TR/webarch/#def-coneg
     """
     if not getattr(self, '_content_type', None):
         raw = self.request.headers.get("Content-Type", MIME['PSJSON'])
         regex = re.findall(
             "(?P<type>\w+\/\w+(\+\w+)?)(;[^;,]*)?([ ]*,[ ]*)?", raw)
         content_type = [k[0] for k in regex]
         for accepted_mime in self._content_types_mime:
             if accepted_mime in content_type:
                 self._content_type = accepted_mime
                 return self._content_type
         raise HTTPError(
             415, "Unsupported content type '%s'" %
             self.request.headers.get("Content-Type", ""))
     return self._content_type
 def accept_content_type(self):
     """
     HTTP has methods to allow the client and the server to negotiate
     the content type for their communication.
     
     Rigth now, this is simple implementation, but additional more complex
     methods can be added in the future.
     
     See:
         http://www.w3.org/Protocols/rfc2616/rfc2616-sec12.html
         
         http://www.ietf.org/rfc/rfc2295.txt
         
         http://httpd.apache.org/docs/2.2/content-negotiation.html
         
         http://www.w3.org/TR/webarch/#def-coneg
     """
     if not getattr(self, '_accept', None):
         self._accept = None
         raw = self.request.headers.get("Accept", MIME['PSJSON'])
         regex = re.findall(
             "(?P<type>(\w+|\*)\/(\w+|\*)(\+\w+)?)(;[^;,]*)?([ ]*,[ ]*)?",
             raw)
         accept = [k[0] for k in regex]
         for accepted_mime in self._accepted_mime:
             if accepted_mime in accept:
                 self._accept = accepted_mime
         if "*/*" in accept:
             self._accept = MIME['JSON']
         if not self._accept:
             raise HTTPError(
                 406, "Unsupported accept content type '%s'" %
                 self.request.headers.get("Accept", None))
     return self._accept
Example #21
0
    def update_invoice(data):
        # 计算所有充值记录之和
        # if not data.get("orders"):
        #     em = "no any more orders id"
        #     LOG.exception(em)
        #     raise HTTPError(400, em)
        # 确认是发票记录是否存在
        invoice_obj = Invoice.query.filter(Invoice.uuid == data.invoice_uuid).first()
        if not invoice_obj:
            em = "can not found any more invoice with id: <{0}>".format(data.invoice_uuid)
            LOG.exception(em)
            raise HTTPError(400, em)
        # # 如果发票状态为邮寄,也不能修改
        # if invoice_obj.status == options.invoice_status.get("posted"):
        #     em = "invoice is posted. can not change"
        #     LOG.exception(em)
        #     raise HTTPError(400, em)
        # update database

        Invoice.query.filter(Invoice.uuid == data.invoice_uuid).update({Invoice.status: data.status,
                                                                        Invoice.complete_date: data.complete_date,
                                                                        Invoice.description: data.description,
                                                                        Invoice.logistics_no: data.logistics_no,
                                                                        Invoice.logistics_company: data.logistics_company,
                                                                        Invoice.invoice_no: data.invoice_no
                                                                        })
        db_session.commit()
        return True
    def post(self, version_key):
        """ Starts an AppServer instance on this machine.

    Args:
      version_key: A string specifying a version key.
    """
        try:
            config = json_decode(self.request.body)
        except ValueError:
            raise HTTPError(HTTPCodes.BAD_REQUEST,
                            'Payload must be valid JSON')

        try:
            yield start_app(version_key, config)
        except BadConfigurationException as error:
            raise HTTPError(HTTPCodes.BAD_REQUEST, error.message)
Example #23
0
 def get(self, id, goods=True):
     cursor = self.conn.cursor()
     page = self.get_argument("page", 1)
     # print int(page), options.pagesize
     try:
         cursor.execute(
             "select nid, cname, dprice, cdesc, ncategoryid, ncount \
                         from tbgoods \
                         where ncategoryid={0} order by nid limit {1} offset {2}"
             .format(id, options.pagesize,
                     options.pagesize * (int(page) - 1)))
     except:
         raise HTTPError(500)
     goods = cursor.fetchall()
     goods_json = [{
         'nid': good[0],
         'cname': good[1],
         'dprice': good[2],
         'cdesc': good[3],
         'ncategoryid': good[4],
         'ncount': good[5]
     } for good in goods]
     # return self.write(json_encode({
     #   'goods':goods_json
     #   }))
     return self.write(json.dumps(goods_json))
Example #24
0
 def get(self, orderid, orderitems, orderitemid):
     cursor = self.conn.cursor()
     try:  # a tborders, b tborderitems
         cursor.execute("select b.nid, b.ngood_id, b.ncount \
                         from tborders as a, \
                         tborderitems as b \
                         where b.norder_id=a.nid \
                         and a.user_id={0} and b.nid={1}".format(
             self.current_user.get("nid"), orderitemid))
     except:
         raise HTTPError(500)
     if cursor.rowcount > 0:
         orderitems = cursor.fetchone()
         cursor.clone()
         return self.write(
             json_encode({
                 'nid': orderitem[0],
                 'ngood_id': orderitem[1],
                 'ncount': orderitem[2]
             }))
     else:
         # return self.write(json_encode({
         #       'orderitem': None
         #   }))
         return self.write(json.dumps([]))
Example #25
0
    def _handle_exception(self, typ, value, tb):
        if self.final_callback:
            self._remove_timeout()
            if isinstance(value, StreamClosedError):
                value = HTTPError(599, "Stream closed")
            self._run_callback(
                HTTPResponse(
                    self.request,
                    599,
                    error=value,
                    request_time=self.io_loop.time() - self.start_time,
                ))

            if hasattr(self, "stream"):
                # TODO: this may cause a StreamClosedError to be raised
                # by the connection's Future.  Should we cancel the
                # connection more gracefully?
                self.stream.close()
            return True
        else:
            # If our callback has already been called, we are probably
            # catching an exception that is not caused by us but rather
            # some child of our callback. Rather than drop it on the floor,
            # pass it along, unless it's just the stream being closed.
            return isinstance(value, StreamClosedError)
Example #26
0
    async def test_api_cvefor_http_error(self, mock_http):
        mock_http.instance().get.side_effect = HTTPError(code=404)

        service = Service()
        service.cpe = self.cpe_txt
        with self.assertRaises(CVESearchApiException):
            await self.task.api_cvefor(service.cpe)
Example #27
0
    def handle_exception(self, typ, error, tb):
        if self._finalized:
            return True

        if self._sent:
            self.force_finish()
            return True

        if isinstance(error, _RequestTimeout):
            if self._stream_ended:
                self.finish()
                return True
            else:
                error = HTTPError(599, "Timeout")

        self._remove_timeout()
        self._unregister_unfinished_streams()
        if hasattr(self, 'stream_id'):
            self.context.remove_stream_delegate(self.stream_id)
            self.context.reset_stream(self.stream_id, flush=True)

        error.__traceback__ = tb
        response = HTTP2Response(
            self.request, 599, error=error,
            request_time=self.io_loop.time() - self.start_time,
        )
        self._run_callback(response)
        return True
Example #28
0
 def _execute(self, transforms, *args, **kwargs):
     """Executes this request with the given output transforms."""
     self._transforms = transforms
     try:
         if self.request.method not in self.SUPPORTED_METHODS:
             raise HTTPError(405)
         # If XSRF cookies are turned on, reject form submissions without
         # the proper cookie
         if self.request.method not in ("GET", "HEAD", "OPTIONS") and \
            self.application.settings.get("xsrf_cookies"):
             self.check_xsrf_cookie()
         # Handles Server Sent Events requests
         if self.decide_content_type() == self.SSE_MIME:
             self._supports_sse = True
             self._last_event_id = self.request.headers.get(
                 "Last-Event-ID", None)
             print("Header 1")
             self.set_header("Cache-Control", "no-cache")
             self.set_header("Content-Type", self.SSE_MIME)
             if self.DEFAULT_RETRY:
                 self.set_retry(self.DEFAULT_RETRY)
         else:
             self._supports_sse = False
         self.prepare()
         if not self._finished:
             args = [self.decode_argument(arg) for arg in args]
             kwargs = dict((k, self.decode_argument(v, name=k))
                           for (k, v) in kwargs.iteritems())
             getattr(self, self.request.method.lower())(*args, **kwargs)
             if self._auto_finish and not self._finished:
                 print("Finish SSE")
                 self.finish()
     except Exception, e:
         self._handle_request_exception(e)
Example #29
0
    def put(self, id):
        '''
        user    :   change its own info [cname]
        admin   :   change anyuser`s info [cname, nrole]
        '''
        if self.current_user['nrole'] == 0:             # user role

            ''' normal user can only change itself '''
            if self.current_user['nid'] != id:
                raise HTTPError(403)

            #user = json.loads(self.request.body)
            #nid, cname = user
            nid = self.get_argument("nid")
            cname = self.get_argument("cname")
            cpassword = self.get_argument("cpassword")

            if nid != id:
                raise HTTPError(403)
            cursor = self.conn.cursor()
            ''' check the id ?'''
            try:
                cursor.execute("update users set cname={0}, cpassword={1} \
                    where nid={2}".format(cname, cpassword, nid))
            except:
                raise HTTPError(500)
            self.conn.commit()
            cursor.close()
            return
        else:                                           # admin role
            #user = json.loads(self.request.body)
            #nid, cname, nrole = user
            nid = self.get_argument("nid")
            cname = self.get_argument("cname")
            cpassword = self.get_argument("cpassword")
            nrole = self.get_argument("nrole")

            cursor = self.conn.cursor()
            ''' check the id ?'''
            try:
                cursor.execute("update users set cname={0}, cpassword={1}, nrole={2} \
                    where nid={3}".format(cname, cpassword, nrole, nid))
            except:
                raise HTTPError(500)
            self.conn.commit()
            cursor.close()
            return
Example #30
0
 def get_with_retries_v2(self,
                         url,
                         websocket=None,
                         max_retry_times=3,
                         as_file=False):
     """
     Use this function.
     """
     try:
         #print("started get_with_retries")
         request = self.simple_request(url)
         http_client = AsyncHTTPClient()
         response = yield http_client.fetch(request)
         result = Result(response, as_file)
     except HTTPError as e:
         msg = "HTTP Exception get_with_retries_v2:{0}".format(e)
         self.printf("{0} {1}".format(e.code, msg))
         try:
             self.printf("TrackingId:{0}".format(
                 e.response.headers.get("Trackingid")))
         except Exception as te:
             self.printf("No TrackingId.")
         try:
             try:
                 msg = json.loads(e.response.body.decode('utf8'))
             except Exception as ex:
                 msg = e.response.body.decode('utf8')
         except Exception as exx:
             pass  #probably a 599 timeout
         #self.printf("New msg: {0}".format(msg))
         if (e.code in [400, 409, 429]
                 or e.code >= 500) and max_retry_times > 0:
             if e.code == 429:
                 retry_after = None
                 try:
                     retry_after = e.response.headers.get("Retry-After")
                 except Exception as e:
                     pass
                 if retry_after == None:
                     retry_after = 30
             else:
                 retry_after = 10
             msg = "{0} hit, waiting for {1} seconds and then retrying...".format(
                 e.code, retry_after)
             self.printf(msg)
             if websocket != None:
                 update_obj = {
                     "resource": "http_error",
                     "message": msg,
                     "update": True
                 }
                 websocket.write_message(json.dumps(update_obj))
             yield tornado.gen.sleep(int(retry_after))
             max_retry_times -= 1
             result = yield self.get_with_retries(url, websocket,
                                                  max_retry_times)
         else:
             raise HTTPError(e.code, response=e.response) from e
     raise tornado.gen.Return(result)