Skip to content
Branch: master
Find file Copy path
Jörn Heissler Add support to pass an SSLContext #74 3216997 Sep 13, 2018
1 contributor

Users who have contributed to this file

41 lines (32 sloc) 1.32 KB
These functions are for making small amounts of async requests.
They construct a temporary Session, returning the resulting response object
to the caller.
from functools import partial
from asks.sessions import Session
__all__ = ['get', 'head', 'post', 'put', 'delete', 'options', 'request']
async def request(method, uri, **kwargs):
'''Base function for one time http requests.
method (str): The http method to use. For example 'GET'
uri (str): The url of the resource.
Example: ''
kwargs: Any number of arguments supported, found here:
Response (asks.Response): The Response object.
c_interact = kwargs.pop('persist_cookies', None)
ssl_context = kwargs.pop('ssl_context', None)
async with Session(persist_cookies=c_interact, ssl_context=ssl_context) as s:
r = await s.request(method, url=uri, **kwargs)
return r
# The functions below are the exact same as the ``request`` function
# above, with the method argument already passed.
get = partial(request, 'GET')
head = partial(request, 'HEAD')
post = partial(request, 'POST')
put = partial(request, 'PUT')
delete = partial(request, 'DELETE')
options = partial(request, 'OPTIONS')
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.