download_attachment
Saves any authenticated school attachment — homework, message, or event files — to a local directory as raw bytes, refusing login pages and avoiding overwrites.
Instructions
Download one attachment from the school to disk. Writes: creates a local file.
Saves any authenticated attachment — homework material, message and event
attachments alike, which is what get_timeline puts in
additional_data.attachements and get_homework_material lists — as the
raw response bytes, never overwriting (a ' (1)', ' (2)', ... suffix is
appended instead). School pages are not attachments: an HTML or login page
is refused rather than written out. Because the bytes go to disk untouched,
this is the only tool that returns a binary attachment intact;
custom_request refuses one.
Args:
url: Absolute attachment URL, or a school-relative path such as
'/elearning/ruqjzfpv?z%3A…' — the exact form
get_timeline(category='recent') returns in
additional_data.attachements — resolved against the school origin.
Any authenticated attachment URL works, not just homework: message
and event attachments included. The request is authenticated with
the school's session.
dest_dir: Directory to save into, created when missing. Defaults to
<tempdir>/homework (e.g. .../AppData/Local/Temp/homework).
filename: Save under this name instead of the server-suggested one.
Directory components and characters illegal on the filesystem are
stripped, so the file always lands directly inside dest_dir.
subdomain: School whose session authenticates the request (defaults to
the active subdomain).
Returns: dict: {'saved_to', 'bytes', 'source_url', 'name'}.
Notes:
- The only tool in this server that writes to disk, and the only one
excluded from the read-only e2e suite — call it only on request.
- Verified live 2026-10-02: a bad or expired attachment token is a
plain HTTP 404, and a school page fetched without a session answers
HTTP 200 with the login page. Both raise instead of writing a file,
so a saved attachment is always real bytes.
- The name comes from content-disposition when the server sends it,
otherwise from the URL path.
- Bounded by the library session's 5 s request timeout
(Edupage(request_timeout=5)), so very large attachments can fail.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | ||
| dest_dir | No | ||
| filename | No | ||
| subdomain | No |