Skip to content

Network

airvpn.web.network

WebSession

Wraps a requests.Session with AirVPN-specific request handling.

Handles the site's JavaScript-check redirect challenge (computing and submitting the required cookie checksum) transparently, and attaches the CSRF key to outgoing requests once available.

Attributes:

Name Type Description
session Session

Underlying requests session used for all HTTP calls.

csrf str | None

CSRF key used to authenticate requests, set after login.

anti_cache str | None

Anti-cache token captured after login.

get_checksum(token: str) -> int

Compute the checksum required to solve AirVPN's JavaScript-check redirect challenge.

Parameters:

Name Type Description Default
token str

The raw token extracted from the challenge redirect URL's aek_id query parameter.

required

Returns:

Type Description
int

The computed checksum value to be set as the af3 cookie.

request(method: str, url: str, **kwargs) -> requests.Response

Perform an HTTP request, transparently handling AirVPN's JavaScript-check redirect challenge if encountered.

The CSRF key (if set) is automatically added to the request's query parameters. If the response indicates the JavaScript-check challenge, this method computes the required checksum, sets it as a cookie, and retries the request against the redirect target.

Parameters:

Name Type Description Default
method str

HTTP method to use (e.g. "get", "post").

required
url str

URL to request.

required
**kwargs

Additional keyword arguments forwarded to requests.Session.request (e.g. data, headers, params).

{}

Returns:

Type Description
Response

requests.Response: The final response, after resolving the JavaScript-check challenge if one was encountered.