Module hdrezka.api.http

Basic wrapper for all http requests of the package

Functions

async def get_response(method: str, url: str | httpx.URL, **kwargs) ‑> httpx.Response
Expand source code
async def get_response(method: str, url: str | httpx.URL, **kwargs) -> httpx.Response:
    """
    passed **kwargs have more weight than DEFAULT_REQUEST_KWARGS.
    Returns DEFAULT_CLIENT.request(method, url, **kwargs, **DEFAULT_REQUEST_KWARGS)
    """
    for k, v in DEFAULT_REQUEST_KWARGS.items():
        if k not in kwargs:
            kwargs[k] = v
    return await DEFAULT_CLIENT.request(method, url, **kwargs)

passed kwargs have more weight than DEFAULT_REQUEST_KWARGS. Returns DEFAULT_CLIENT.request(method, url, kwargs, **DEFAULT_REQUEST_KWARGS)

async def login_global(email: str, password: str)
Expand source code
async def login_global(email: str, password: str):
    """
    It enters the site using `DEFAULT_CLIENT`.
    Updates the global `HOST` to bypass the blocking, and `DEFAULT_CLIENT` cookies.
    """
    _follow_redirects = DEFAULT_CLIENT.follow_redirects
    DEFAULT_CLIENT.follow_redirects = False
    resp = await get_response('GET', Request.REDIRECT_URL)
    DEFAULT_CLIENT.follow_redirects = _follow_redirects
    url = httpx.URL(resp.headers.get('Location', resp.url))
    ajax_login_url = url.join('/ajax/login/')

    await get_response(
        'POST', ajax_login_url,
        data={'login_name': email, 'login_password': password, 'login_not_save': '0', 'login': 'submit'})
    Request.HOST = f'https://{url.host}'

It enters the site using DEFAULT_CLIENT. Updates the global HOST to bypass the blocking, and DEFAULT_CLIENT cookies.