本文整理汇总了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)
示例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
示例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', '/')