# pydoc > problem_report

---
type: CommandReference
command: problem_report
mode: pydoc
section: ""
source: pydoc3
---

## Quick Reference

- `ProblemReport(type='Crash')` — create a new problem report with given type
- `ProblemReport.load(file, binary=True, key_filter=None)` — load report from file-like object
- `ProblemReport.write(file, only_new=False)` — write report to file-like object
- `ProblemReport.write_mime(file, ...)` — write MIME/Multipart formatted data
- `CompressedValue(value=None, name=None)` — represent a gzip compressed value

## Name

Store, load, and handle problem reports.

## Synopsis

The `problem_report` module provides classes to represent and manipulate problem reports (e.g., Apport crash reports). It supports loading from and writing to RFC822 format files, with optional compression and MIME output.

## Options

### Class `CompressedValue`

- `CompressedValue(value=None, name=None)` — initialize an empty compressed value with optional name
- `__len__()` — return length of uncompressed value
- `get_value()` — return uncompressed value
- `set_value(value)` — set uncompressed value
- `splitlines()` — behave like `splitlines()` for a normal string
- `write(file)` — write uncompressed value into given file-like object

### Class `ProblemReport`

- `ProblemReport(type='Crash', date=None)` — initialize a fresh problem report. `type` can be 'Crash', 'Packaging', 'KernelCrash', or 'KernelOops'. `date` defaults to current local time.
- `__setitem__(k, v)` — set a key-value pair
- `add_to_existing(reportfile, keep_times=False)` — add this report's data to an existing report file. The file is temporarily chmod'ed to 000 to prevent frontend pickup. If `keep_times` is True, atime and mtime are restored.
- `extract_keys(file, bin_keys, dir)` — extract only one binary element (e.g., kernel crash dumps) directly from the file without loading into memory.
- `get_timestamp()` — return timestamp (seconds since epoch) from Date field, or None if absent.
- `has_removed_fields()` — check if report has keys that were not loaded (may happen when `binary=False` in `load()`).
- `load(file, binary=True, key_filter=None)` — initialize problem report from a file-like object opened in binary mode. If `binary` is False, binary data is not loaded (value becomes empty string). If True, values are uncompressed and available as byte arrays. If 'compressed', the compressed value is retained as a `CompressedValue` object. `key_filter` restricts loaded keys.
- `new_keys()` — return set of keys added since construction or last `load()`.
- `write(file, only_new=False)` — write report to file-like object opened in binary mode. If `only_new` is True, only keys added since last `load()` are written. Values can be strings or tuples of `(file, encode=True, limit=None, fail_on_empty=False)`. `encode` defaults to True (gzip compression and base64 encoding). If `limit` is set, a file larger than the limit is not attached and the key is removed. If `fail_on_empty` is True, reading zero bytes raises IOError.
- `write_mime(file, attach_treshold=5, extra_headers={}, skip_keys=None, priority_fields=None)` — write MIME/Multipart RFC 2822 formatted data. `file` must be opened in binary mode. Values are strings, CompressedValue, or tuples of (source file, optional boolean). Files are gzip compressed unless key ends in .gz. `attach_treshold` is max lines for inline text; larger or non-ASCII values become attachments. Text values >1 kB also become attachments. `extra_headers` is a dict of additional MIME headers. `skip_keys` filters out keys. `priority_fields` specifies ordering.

## See Also

- [apport](https://manpages.ubuntu.com/manpages/latest/man1/apport.1.html) — related problem reporting tools

## File

`/usr/lib/python3/dist-packages/problem_report.py`