asyncio
Warning
async http
Async http calls are available through the self.async_http object in rule instances.
Functions
- delete(url, params=None, **kwargs)
http delete request
- Parameters:
url (
str) – Request URLparams (
Mapping[str,str] |None) – Mapping, iterable of tuple of key/value pairs (e.g. dict) to be sent as parameters in the query string of the new request. Params examplekwargs (
Any) – See aiohttp request for further possible kwargs
- Return type:
_BaseRequestContextManager[ClientResponse]- Returns:
awaitable
- get(url, params=None, **kwargs)
http get request
- Parameters:
url (
str) – Request URLparams (
Mapping[str,str] |None) –Mapping, iterable of tuple of key/value pairs (e.g. dict) to be sent as parameters in the query string of the new request. Params example
kwargs (
Any) –See aiohttp request for further possible kwargs
- Return type:
_BaseRequestContextManager[ClientResponse]- Returns:
awaitable
- get_client_session()
Return the aiohttp client session object for use in aiohttp libraries
- Return type:
ClientSession- Returns:
session object
- post(url, params=None, data=None, json=None, **kwargs)
http post request
- Parameters:
url (
str) – Request URLparams (
Mapping[str,str] |None) –Mapping, iterable of tuple of key/value pairs (e.g. dict) to be sent as parameters in the query string of the new request. Params example
data (
Any) – Dictionary, bytes, or file-like object to send in the body of the request (optional)json (
Any) – Any json compatible python object, json and data parameters could not be used at the same time. (optional)kwargs (
Any) –See aiohttp request for further possible kwargs
- Return type:
_BaseRequestContextManager[ClientResponse]- Returns:
awaitable
- put(url, params=None, data=None, json=None, **kwargs)
http put request
- Parameters:
url (
str) – Request URLparams (
Mapping[str,str] |None) –Mapping, iterable of tuple of key/value pairs (e.g. dict) to be sent as parameters in the query string of the new request. Params example
data (
Any) – Dictionary, bytes, or file-like object to send in the body of the request (optional)json (
Any) – Any json compatible python object, json and data parameters could not be used at the same time. (optional)kwargs (
Any) –See aiohttp request for further possible kwargs
- Return type:
_BaseRequestContextManager[ClientResponse]- Returns:
awaitable
Examples
import asyncio
import HABApp
class AsyncRule(HABApp.Rule):
def __init__(self) -> None:
super().__init__()
self.run.soon(self.async_func)
async def async_func(self) -> None:
await asyncio.sleep(2)
async with self.async_http.get('http://httpbin.org/get') as resp:
print(resp)
print(await resp.text())
AsyncRule()