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


Python aiohttp.HttpProcessingError方法代码示例

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


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

示例1: get_flag

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import HttpProcessingError [as 别名]
def get_flag(base_url, cc):
    url = '{}/{cc}/{cc}.gif'.format(base_url, cc=cc.lower())
    resp = yield from aiohttp.request('GET', url)
    with contextlib.closing(resp):
        if resp.status == 200:
            image = yield from resp.read()
            return image
        elif resp.status == 404:
            raise web.HTTPNotFound()
        else:
            raise aiohttp.HttpProcessingError(
                code=resp.status, message=resp.reason,
                headers=resp.headers)


# BEGIN FLAGS2_ASYNCIO_EXECUTOR 
开发者ID:fluentpython,项目名称:notebooks,代码行数:18,代码来源:flags2_asyncio_executor.py

示例2: test_dispatch_not_found

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import HttpProcessingError [as 别名]
def test_dispatch_not_found(self):
        m = mock.Mock()
        self.server.add_url('post', '/post/{id}', m)
        self.server.add_url('get', '/post/{id}', m)

        @asyncio.coroutine
        def go():
            with self.assertRaises(aiohttp.HttpProcessingError) as ctx:
                request = Request('host', aiohttp.RawRequestMessage(
                    'POST', '/not/found', '1.1', {}, True, None),
                    None, loop=self.loop)
                yield from self.server.dispatch(request)
            self.assertEqual(404, ctx.exception.code)

        self.assertFalse(m.called)
        self.loop.run_until_complete(go()) 
开发者ID:aio-libs-abandoned,项目名称:aiorest,代码行数:18,代码来源:router_test.py

示例3: test_dispatch_method_not_allowed

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import HttpProcessingError [as 别名]
def test_dispatch_method_not_allowed(self):
        m = mock.Mock()
        self.server.add_url('post', '/post/{id}', m)
        self.server.add_url('get', '/post/{id}', m)

        @asyncio.coroutine
        def go():
            with self.assertRaises(aiohttp.HttpProcessingError) as ctx:
                request = Request('host', aiohttp.RawRequestMessage(
                    'DELETE', '/post/123', '1.1', {}, True, None),
                    None, loop=self.loop)
                yield from self.server.dispatch(request)
            self.assertEqual(405, ctx.exception.code)
            self.assertEqual((('Allow', 'GET, POST'),), ctx.exception.headers)

        self.assertFalse(m.called)
        self.loop.run_until_complete(go()) 
开发者ID:aio-libs-abandoned,项目名称:aiorest,代码行数:19,代码来源:router_test.py

示例4: test_dispatch_bad_signature

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import HttpProcessingError [as 别名]
def test_dispatch_bad_signature(self):
        def f():
            return {'a': 1, 'b': 2}
        self.server.add_url('get', '/post/{id}', f)

        request = Request('host', aiohttp.RawRequestMessage(
            'GET', '/post/123', '1.1', {}, True, None),
            None, loop=self.loop)

        @asyncio.coroutine
        def go():
            with self.assertRaises(aiohttp.HttpProcessingError) as ctx:
                yield from self.server.dispatch(request)
            self.assertEqual(500, ctx.exception.code)

        self.loop.run_until_complete(go()) 
开发者ID:aio-libs-abandoned,项目名称:aiorest,代码行数:18,代码来源:router_test.py

示例5: verifyDomain

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import HttpProcessingError [as 别名]
def verifyDomain(domain):
    """ create domain if it doesn't already exist
    """
    params = {"host": domain}
    headers = getRequestHeaders()
    client = globals["client"]
    req = getEndpoint() + '/'
    root_id = None
    log.info("GET " + req)
    globals["request_count"] += 1
    timeout = config.get("timeout")
    async with client.get(req, headers=headers, params=params, timeout=timeout) as rsp:
        if rsp.status == 200:
            domain_json = await rsp.json()
        else:
            log.info("got status: {}".format(rsp.status))
    if rsp.status == 200:
        root_id = domain_json["root"]
    elif rsp.status == 404:
        # create the domain
        log.info("PUT " + req)
        globals["request_count"] += 1
        async with client.put(req, headers=headers, params=params, timeout=timeout) as rsp:
            if rsp.status != 201:
                log.error("got status: {} for PUT req: {}".format(rsp.status, req))
                raise HttpProcessingError(code=rsp.status, message="Unexpected error")
        log.info("GET " + req)
        globals["request_count"] += 1
        async with client.get(req, headers=headers, params=params, timeout=timeout) as rsp:
            if rsp.status == 200:
                domain_json = await rsp.json()
                root_id = domain_json["root"]
            else:
                log.error("got status: {} for GET req: {}".format(rsp.status, req))
                raise HttpProcessingError(code=rsp.status, message="Service error")
    globals["root"] = root_id 
开发者ID:HDFGroup,项目名称:hsds,代码行数:38,代码来源:import_ghcn_file.py

示例6: verifyDomain

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import HttpProcessingError [as 别名]
def verifyDomain(domain):
    """ create domain if it doesn't already exist
    """
    params = {"host": domain}
    headers = getRequestHeaders()
    client = globals["client"]
    req = getEndpoint() + '/'
    root_id = None
    log.info("GET " + req)
    timeout = config.get("timeout")
    async with client.get(req, headers=headers, timeout=timeout, params=params) as rsp:
        if rsp.status == 200:
            domain_json = await rsp.json()
        else:
            log.info("got status: {}".format(rsp.status))
    if rsp.status == 200:
        root_id = domain_json["root"]
    elif rsp.status == 404:
        # create the domain
        setupDomain(domain)
        async with client.get(req, headers=headers, timeout=timeout, params=params) as rsp:
            if rsp.status == 200:
                domain_json = await rsp.json()
                root_id = domain_json["root"]
            else:
                log.error("got status: {} for GET req: {}".format(rsp.status, req))
                raise HttpProcessingError(code=rsp.status, message="Service error")
    globals["root"] = root_id 
开发者ID:HDFGroup,项目名称:hsds,代码行数:30,代码来源:mkgroups.py

示例7: get_flag

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import HttpProcessingError [as 别名]
def get_flag(client, base_url, cc):
    url = '{}/{cc}/{cc}.gif'.format(base_url, cc=cc.lower())
    async with client.get(url) as resp:
        if resp.status == 200:
            return await resp.read()
        elif resp.status == 404:
            raise web.HTTPNotFound()
        else:
            raise aiohttp.HttpProcessingError(
                code=resp.status, message=resp.reason,
                headers=resp.headers) 
开发者ID:fluentpython,项目名称:concurrency2017,代码行数:13,代码来源:flags2_await.py

示例8: get_flag

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import HttpProcessingError [as 别名]
def get_flag(base_url, cc): # <2>
    url = '{}/{cc}/{cc}.gif'.format(base_url, cc=cc.lower())
    resp = yield from aiohttp.request('GET', url)
    with contextlib.closing(resp):
        if resp.status == 200:
            image = yield from resp.read()
            return image
        elif resp.status == 404:
            raise web.HTTPNotFound()
        else:
            raise aiohttp.HttpProcessingError(
                code=resp.status, message=resp.reason,
                headers=resp.headers) 
开发者ID:fluentpython,项目名称:notebooks,代码行数:15,代码来源:flags2_asyncio.py

示例9: get_flag

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import HttpProcessingError [as 别名]
def get_flag(base_url, cc): # <2>
    url = '{}/{cc}/{cc}.gif'.format(base_url, cc=cc.lower())
    with closing(await aiohttp.request('GET', url)) as resp:
        if resp.status == 200:
            image = await resp.read()
            return image
        elif resp.status == 404:
            raise web.HTTPNotFound()
        else:
            raise aiohttp.HttpProcessingError(
                code=resp.status, message=resp.reason,
                headers=resp.headers) 
开发者ID:fluentpython,项目名称:notebooks,代码行数:14,代码来源:flags2_await.py

示例10: send

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import HttpProcessingError [as 别名]
def send(self):
        async with aiohttp.ClientSession() as client_session:
            async with client_session.post(self.backend, data=self.request) as res:
                if res.status != 200:
                    raise aiohttp.HttpProcessingError(res.status)

                data = await res.read()
                data = data.decode('utf-8')
                return data.replace(data[:16], '') # remove token 
开发者ID:FrenchMasterSword,项目名称:RTFMbot,代码行数:11,代码来源:_tio.py

示例11: get_flag

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import HttpProcessingError [as 别名]
def get_flag(session, base_url, cc): # <2>
    url = '{}/{cc}/{cc}.gif'.format(base_url, cc=cc.lower())
    async with session.get(url) as resp:
        if resp.status == 200:
            return await resp.read()
        elif resp.status == 404:
            raise web.HTTPNotFound()
        else:
            raise aiohttp.HttpProcessingError(
                code=resp.status, message=resp.reason,
                headers=resp.headers) 
开发者ID:fluentpython,项目名称:example-code,代码行数:13,代码来源:flags2_asyncio.py

示例12: test_dispatch_with_ending_slash_not_found1

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import HttpProcessingError [as 别名]
def test_dispatch_with_ending_slash_not_found1(self):
        def f(request):
            return {'a': 1, 'b': 2}
        self.server.add_url('get', '/post/{id}/', f)

        request = Request('host', aiohttp.RawRequestMessage(
            'GET', '/post/123', '1.1', {}, True, None),
            None, loop=self.loop)

        with self.assertRaises(aiohttp.HttpProcessingError) as ctx:
            self.loop.run_until_complete(self.server.dispatch(request))
        self.assertEqual(404, ctx.exception.code) 
开发者ID:aio-libs-abandoned,项目名称:aiorest,代码行数:14,代码来源:router_test.py

示例13: test_dispatch_with_ending_slash_not_found2

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import HttpProcessingError [as 别名]
def test_dispatch_with_ending_slash_not_found2(self):
        def f(request):
            return {'a': 1, 'b': 2}
        self.server.add_url('get', '/post/{id}/', f)

        request = Request('host', aiohttp.RawRequestMessage(
            'GET', '/po/123', '1.1', {}, True, None),
            None, loop=self.loop)

        with self.assertRaises(aiohttp.HttpProcessingError) as ctx:
            self.loop.run_until_complete(self.server.dispatch(request))
        self.assertEqual(404, ctx.exception.code) 
开发者ID:aio-libs-abandoned,项目名称:aiorest,代码行数:14,代码来源:router_test.py

示例14: createGroup

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import HttpProcessingError [as 别名]
def createGroup(parent_group, group_name):
    """ create a new group and link it to the parent group with 
    link name of group name
    """
    client = globals["client"]
    domain = globals["domain"]
    params = {"host": domain}
    base_req = getEndpoint()
    headers = getRequestHeaders()
    timeout = config.get("timeout")

    # TBD - replace with atomic create & link operation?
    
    # create a new group
    req = base_req + "/groups"
    log.info("POST:" + req)
    globals["request_count"] += 1
    async with client.post(req, headers=headers, params=params, timeout=timeout) as rsp:
        if rsp.status != 201:
            log.error("POST {} failed with status: {}, rsp: {}".format(req, rsp.status, str(rsp)))
            raise HttpProcessingError(code=rsp.status, message="Unexpected error")
        group_json = await rsp.json()
        group_id = group_json["id"]

    # link group to parent
    req = base_req + "/groups/" + parent_group + "/links/" + group_name
    data = {"id": group_id }
    link_created = False
    log.info("PUT " + req)
    globals["request_count"] += 1
    async with client.put(req, data=json.dumps(data), headers=headers, params=params, timeout=timeout) as rsp:
        if rsp.status == 409:
            # another task has created this link already
            log.warn("got 409 in request: " + req)
        elif rsp.status != 201:
            log.error("got http error: {} for request: {}, rsp: {}".format(rsp.status, req, rsp))
            raise HttpProcessingError(code=rsp.status, message="Unexpected error")
        else:
            link_created = True

    if not link_created:
        # fetch the existing link and return the group 
        log.info("GET " + req)
        globals["request_count"] += 1
        async with client.get(req, headers=headers, params=params, timeout=timeout) as rsp:
            if rsp.status != 200:
                log.warn("unexpected error (expected to find link) {} for request: {}".format(rsp.status, req))
                raise HttpProcessingError(code=rsp.status, message="Unexpected error")
            else:
                rsp_json = await rsp.json()
                link_json = rsp_json["link"]
                if link_json["class"] != "H5L_TYPE_HARD":
                    raise ValueError("Unexpected Link type: {}".format(link_json))
                group_id = link_json["id"]
    
    return group_id 
开发者ID:HDFGroup,项目名称:hsds,代码行数:58,代码来源:import_ghcn_file.py

示例15: verifyGroupPath

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import HttpProcessingError [as 别名]
def verifyGroupPath(h5path):
    """ create any groups along the path that doesn't exist
    """
    #print("current task: ", asyncio.Task.current_task())
    client = globals["client"]
    domain = globals["domain"]
    h5path_cache = globals["h5path_cache"]
    params = {"host": domain}
    parent_group = h5path_cache['/']  # start with root
    group_names = h5path.split('/')
    
    headers = getRequestHeaders()
    
    base_req = getEndpoint() + '/groups/'
    next_path = '/'
    timeout = config.get("timeout")

    for group_name in group_names:
        if not group_name:
            continue  # skip empty names
        next_path += group_name
        if not next_path.endswith('/'):
            next_path += '/'  # prep for next roundtrips
        if next_path in h5path_cache:
            # we already have the group id
            parent_group = h5path_cache[next_path]    
            continue
        
        req = base_req + parent_group + "/links/" + group_name
        log.info("GET " + req)
        globals["request_count"] += 1
        async with client.get(req, headers=headers, params=params, timeout=timeout) as rsp:
            if rsp.status == 404:
                parent_group = await createGroup(parent_group, group_name)
            elif rsp.status != 200:
                raise HttpProcessingError(code=rsp.status, message="Unexpected error")
            else:
                rsp_json = await rsp.json()
                link_json = rsp_json["link"]
                if link_json["class"] != "H5L_TYPE_HARD":
                    raise ValueError("Unexpected Link type: {}".format(link_json))
                parent_group = link_json["id"]
                h5path_cache[next_path] = parent_group
    
    return parent_group 
开发者ID:HDFGroup,项目名称:hsds,代码行数:47,代码来源:import_ghcn_file.py


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