当前位置: 首页>>代码示例>>Python>>正文


Python httpclient.HTTPError方法代码示例

本文整理汇总了Python中tornado.httpclient.HTTPError方法的典型用法代码示例。如果您正苦于以下问题:Python httpclient.HTTPError方法的具体用法?Python httpclient.HTTPError怎么用?Python httpclient.HTTPError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tornado.httpclient的用法示例。


在下文中一共展示了httpclient.HTTPError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _handle_exception

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPError [as 别名]
def _handle_exception(self, typ, value, tb):
        if self.final_callback:
            self._remove_timeout()
            if isinstance(value, StreamClosedError):
                if value.real_error is None:
                    value = HTTPError(599, "Stream closed")
                else:
                    value = value.real_error
            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) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:26,代码来源:simple_httpclient.py

示例2: AllocateIds

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPError [as 别名]
def AllocateIds(asset_types, user_cookie):
  http_headers = {
    'Cookie': '_xsrf=fake_xsrf; user=%s' % user_cookie,
    'X-XSRFToken': 'fake_xsrf',
    'Content-Type': 'application/json'
    }
  body = {
    'headers': {
      'version': MAX_SUPPORTED_MESSAGE_VERSION
      },
    'asset_types': asset_types
    }
  try:
    response = _CallService('/service/allocate_ids', body, http_headers)
  except HTTPError:
    return None
  else:
    return json.loads(response.body) 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:20,代码来源:run-ui-tests.py

示例3: TerminateUser

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPError [as 别名]
def TerminateUser(info_dict, login_resp):
  http_headers = {
    'Cookie': '_xsrf=fake_xsrf; user=%s' % login_resp['cookie'],
    'X-XSRFToken': 'fake_xsrf',
    'Content-Type': 'application/json'
    }
  body = {
    'headers': login_resp['headers'],
    }

  op_id = AllocateIds(['o'], login_resp['cookie'])
  if op_id is not None:
    body['headers']['op_id'] = op_id['asset_ids'][0]

  try:
    response = _CallService('/service/terminate_account', body, http_headers)
  except HTTPError:
    return None;
  else:
    return json.loads(response.body) 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:22,代码来源:run-ui-tests.py

示例4: test_app_auth_with_invalid_pubkey_for_user_robey

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPError [as 别名]
def test_app_auth_with_invalid_pubkey_for_user_robey(self):
        url = self.get_url('/')
        privatekey = 'h' * 1024
        files = [('privatekey', 'user_rsa_key', privatekey)]
        content_type, body = encode_multipart_formdata(self.body_dict.items(),
                                                       files)
        headers = {
            'Content-Type': content_type, 'content-length': str(len(body))
        }

        if swallow_http_errors:
            response = yield self.async_post(url, body, headers=headers)
            self.assertIn(b'Invalid key', response.body)
        else:
            with self.assertRaises(HTTPError) as ctx:
                yield self.async_post(url, body, headers=headers)
            self.assertIn('Bad Request', ctx.exception.message) 
开发者ID:huashengdun,项目名称:webssh,代码行数:19,代码来源:test_app.py

示例5: test_app_auth_with_pubkey_exceeds_key_max_size

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPError [as 别名]
def test_app_auth_with_pubkey_exceeds_key_max_size(self):
        url = self.get_url('/')
        privatekey = 'h' * (handler.PrivateKey.max_length + 1)
        files = [('privatekey', 'user_rsa_key', privatekey)]
        content_type, body = encode_multipart_formdata(self.body_dict.items(),
                                                       files)
        headers = {
            'Content-Type': content_type, 'content-length': str(len(body))
        }
        if swallow_http_errors:
            response = yield self.async_post(url, body, headers=headers)
            self.assertIn(b'Invalid key', response.body)
        else:
            with self.assertRaises(HTTPError) as ctx:
                yield self.async_post(url, body, headers=headers)
            self.assertIn('Bad Request', ctx.exception.message) 
开发者ID:huashengdun,项目名称:webssh,代码行数:18,代码来源:test_app.py

示例6: test_app_auth_with_pubkey_cannot_be_decoded_by_multipart_form

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPError [as 别名]
def test_app_auth_with_pubkey_cannot_be_decoded_by_multipart_form(self):
        url = self.get_url('/')
        privatekey = 'h' * 1024
        files = [('privatekey', 'user_rsa_key', privatekey)]
        content_type, body = encode_multipart_formdata(self.body_dict.items(),
                                                       files)
        body = body.encode('utf-8')
        # added some gbk bytes to the privatekey, make it cannot be decoded
        body = body[:-100] + b'\xb4\xed\xce\xf3' + body[-100:]
        headers = {
            'Content-Type': content_type, 'content-length': str(len(body))
        }
        if swallow_http_errors:
            response = yield self.async_post(url, body, headers=headers)
            self.assertIn(b'Invalid unicode', response.body)
        else:
            with self.assertRaises(HTTPError) as ctx:
                yield self.async_post(url, body, headers=headers)
            self.assertIn('Bad Request', ctx.exception.message) 
开发者ID:huashengdun,项目名称:webssh,代码行数:21,代码来源:test_app.py

示例7: _get_dmm_token

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPError [as 别名]
def _get_dmm_token(self):
        try:
            req = yield self.http_client.fetch(dmm.LOGIN_URL, headers=self.headers,
                                               connect_timeout=self.connect_timeout,
                                               request_timeout=self.request_timeout,
                                               proxy_host=proxy_host, proxy_port=proxy_port)
        except (CurlError, HTTPError):
            raise OoiAuthError('连接DMM网站失败')

        body = native_str(req.body)
        m = self.dmm_token_pattern.search(body)
        if m:
            dmm_token = m.group(1)
        else:
            raise OoiAuthError('获取DMM token失败')
        m = self.token_pattern.search(body)
        if m:
            token = m.group(1)
        else:
            raise OoiAuthError('获取token失败')

        return dmm_token, token 
开发者ID:acgx,项目名称:ooi2,代码行数:24,代码来源:kancolle.py

示例8: _get_ajax_token

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPError [as 别名]
def _get_ajax_token(self, dmm_token, token):
        self.headers.update({'Origin': 'https://www.dmm.com',
                             'Referer': dmm.LOGIN_URL,
                             'Cookie': 'ckcy=1; check_open_login=1; check_down_login=1',
                             'DMM_TOKEN': dmm_token,
                             'X-Requested-With': 'XMLHttpRequest'})
        body = urlencode({'token': token})
        try:
            req = yield self.http_client.fetch(dmm.AJAX_TOKEN_URL, method='POST', headers=self.headers, body=body,
                                               connect_timeout=self.connect_timeout,
                                               request_timeout=self.request_timeout,
                                               proxy_host=proxy_host, proxy_port=proxy_port)
        except (CurlError, HTTPError):
            raise OoiAuthError('DMM网站AJAX请求失败')
        j = json_decode(native_str(req.body))
        return j['token'], j['login_id'], j['password'] 
开发者ID:acgx,项目名称:ooi2,代码行数:18,代码来源:kancolle.py

示例9: _get_world

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPError [as 别名]
def _get_world(self, osapi_url):
        qs = parse_qs(urlparse(osapi_url).query)
        owner = qs['owner'][0]
        self.owner = owner
        st = qs['st'][0]
        url = dmm.GET_WORLD_URL % (owner, int(time.time()*1000))
        self.headers['Referer'] = osapi_url
        try:
            req = yield self.http_client.fetch(url, headers=self.headers,
                                               connect_timeout=self.connect_timeout,
                                               request_timeout=self.request_timeout,
                                               proxy_host=proxy_host, proxy_port=proxy_port)
        except (CurlError, HTTPError):
            raise OoiAuthError('获取服务器ID失败')
        svdata = json_decode(native_str(req.body)[7:])
        if svdata['api_result'] == 1:
            world_id = svdata['api_data']['api_world_id']
        else:
            raise OoiAuthError('服务器ID错误')
        return world_id, st 
开发者ID:acgx,项目名称:ooi2,代码行数:22,代码来源:kancolle.py

示例10: proxy_package

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPError [as 别名]
def proxy_package(cls, package):
        try:
            remote_package_exists = yield PYPIClient.exists(package)

            if remote_package_exists:
                pkg_real_name = yield PYPIClient.find_real_name(package)
                pkg = yield proxy_remote_package(pkg_real_name)

                raise Return(pkg)

            raise LookupError("Remote package not found")
        except (LookupError, HTTPClientError) as e:
            if isinstance(e, HTTPClientError):
                log.warning("PYPI backend return an error: %s", e)

            raise Return(Package.find(package)) 
开发者ID:mosquito,项目名称:pypi-server,代码行数:18,代码来源:files.py

示例11: check_access

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPError [as 别名]
def check_access(handler, roleneed):
    
    if isinstance(roleneed,MasterRoleNeed):
        return
    
    if not roleneed:
	raise HTTPError(403)

    checkname = handler.__checkname__
    if handler.__needcheck__.get('url',None):
        if not checkname in roleneed.nodes:
            raise HTTPError(403)

    ctx_params = handler.__needcheck__.get('ctx_param',None)
    if ctx_params:
        for ctx_param in ctx_params.split(','):
            ctx_val = handler.get_argument(ctx_param, handler.path_kwargs.get(ctx_param,None))
            if not ctx_val in roleneed.ctx_vals.get(ctx_param,()):
                raise HTTPError(403) 
开发者ID:comger,项目名称:tor_access,代码行数:21,代码来源:__init__.py

示例12: _request

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPError [as 别名]
def _request(self, callback, request):
        try:
            response = yield self.client.fetch(request)
        except httpclient.HTTPError as e:
            if e.code == 599:
                raise base.Timeout
            response = e.response
        raise gen.Return(callback(self.response(response))) 
开发者ID:poppyred,项目名称:python-consul2,代码行数:10,代码来源:tornado.py

示例13: _on_timeout

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPError [as 别名]
def _on_timeout(self, key):
        request, callback, timeout_handle = self.waiting[key]
        self.queue.remove((key, request, callback))
        timeout_response = HTTPResponse(
            request, 599, error=HTTPError(599, "Timeout"),
            request_time=self.io_loop.time() - request.start_time)
        self.io_loop.add_callback(callback, timeout_response)
        del self.waiting[key] 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:10,代码来源:simple_httpclient.py

示例14: on_connection_close

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPError [as 别名]
def on_connection_close(self):
        if self.final_callback is not None:
            message = "Connection closed"
            if self.stream.error:
                raise self.stream.error
            try:
                raise HTTPError(599, message)
            except HTTPError:
                self._handle_exception(*sys.exc_info()) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:11,代码来源:simple_httpclient.py

示例15: test_websocket_http_fail

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPError [as 别名]
def test_websocket_http_fail(self):
        with self.assertRaises(HTTPError) as cm:
            yield self.ws_connect('/notfound')
        self.assertEqual(cm.exception.code, 404) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:6,代码来源:websocket_test.py


注:本文中的tornado.httpclient.HTTPError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。