mt.base.http
Useful subroutines dealing with downloading http files.
Functions
download()
: An asyn function that opens a binary file and reads the content.download_and_chmod()
: An asyn function that downloads an http or https url as binary to a file with predefined permissions.
- async mt.base.http.download(url, context_vars: dict = {})
An asyn function that opens a binary file and reads the content.
- Parameters:
url (str) – a http or https URL
asyn (bool) – whether the function is to be invoked asynchronously or synchronously
context_vars (dict) – a dictionary of context variables within which the function runs. It must include context_vars[‘async’] to tell whether to invoke the function asynchronously or not. In asynchronous mode, variable ‘http_session’ must exist and hold an enter-result of an async with statement invoking
create_http_session()
.
- Returns:
the content downloaded from the web
- Return type:
bytes
- Raises:
ConnectionAbortedError – if there is a problem downloading
PermissionError – if forbidden word “Access Denied” or “AccessDenied” is detected
- async mt.base.http.download_and_chmod(url, filepath, file_mode=436, context_vars: dict = {})
An asyn function that downloads an http or https url as binary to a file with predefined permissions.
- Parameters:
url (str) – an http or https url
filepath (str) – file location to save the content to
file_mode (int) – to be passed directly to os.chmod() if not None
context_vars (dict) – a dictionary of context variables within which the function runs. It must include context_vars[‘async’] to tell whether to invoke the function asynchronously or not. In asynchronous mode, variable ‘http_session’ must exist and hold an enter-result of an async with statement invoking
create_http_session()
.