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


Python ClientSession.request方法代码示例

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


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

示例1: go

# 需要导入模块: from aiohttp.client import ClientSession [as 别名]
# 或者: from aiohttp.client.ClientSession import request [as 别名]
        def go():
            err = OSError(1, "permission error")
            req = mock.Mock()
            req_factory = mock.Mock(return_value=req)
            req.send = mock.Mock(side_effect=err)
            session = ClientSession(loop=self.loop, request_class=req_factory)

            @asyncio.coroutine
            def create_connection(req):
                # return self.transport, self.protocol
                return mock.Mock(), mock.Mock()
            session._connector._create_connection = create_connection

            with self.assertRaises(aiohttp.ClientOSError) as ctx:
                yield from session.request('get', 'http://example.com')
            e = ctx.exception
            self.assertEqual(e.errno, err.errno)
            self.assertEqual(e.strerror, err.strerror)
开发者ID:flying-sheep,项目名称:aiohttp,代码行数:20,代码来源:test_client_session.py

示例2: fetch

# 需要导入模块: from aiohttp.client import ClientSession [as 别名]
# 或者: from aiohttp.client.ClientSession import request [as 别名]
 async def fetch(self, request: Request, session: ClientSession):
     if self.use_proxy:
         # method, url, *,
         # params = None,
         # data = None,
         # json = None,
         # headers = None,
         # skip_auto_headers = None,
         # auth = None,
         # allow_redirects = True,
         # max_redirects = 10,
         # compress = None,
         # chunked = None,
         pass
     try:
         biu = session.request(request.method, request.url,
                               headers=request.header,
                               data=request.body)
         async with biu as req:
             text = await req.text()
             return Response(request, text, req.status)
     except Exception:
         pass
开发者ID:LooEv,项目名称:learning-python,代码行数:25,代码来源:spider_engine.py

示例3: go

# 需要导入模块: from aiohttp.client import ClientSession [as 别名]
# 或者: from aiohttp.client.ClientSession import request [as 别名]
 def go():
     session = ClientSession(loop=self.loop)
     session.close()
     with self.assertRaises(RuntimeError):
         yield from session.request('get', '/')
开发者ID:morgan-del,项目名称:aiohttp,代码行数:7,代码来源:test_client_session.py


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