pyrfc6266
raw JSON → 1.0.2 verified Fri May 01 auth: no python
A Python implementation of RFC 6266 for parsing Content-Disposition headers. Version 1.0.2 is the current stable release. Low release cadence; last updated in 2021.
pip install pyrfc6266 Common errors
error AttributeError: 'ContentDisposition' object has no attribute 'filename' ↓
cause Accessing nonexistent attribute; correct attribute is 'filename_utf8' or 'raw_filename'.
fix
Use
cd.filename_utf8 instead of cd.filename. error ImportError: cannot import name 'parse_content_disposition' from 'pyrfc6266' ↓
cause Using an incorrect function name; the correct class is `ContentDisposition`.
fix
Use
from pyrfc6266 import ContentDisposition and call ContentDisposition.parse(header). Warnings
gotcha The `filename` attribute returns the raw, possibly percent-encoded value from the header; use `filename_utf8` for the decoded UTF-8 filename. ↓
fix Always use `filename_utf8` instead of `filename` for human-readable filenames.
gotcha The library does not support extended attributes like `filename*` as defined in RFC 5987. It only parses `filename` parameters. ↓
fix If you need RFC 5987 support, consider a different library or implement it yourself.
Imports
- ContentDisposition
from pyrfc6266 import ContentDisposition
Quickstart
from pyrfc6266 import ContentDisposition
header = 'attachment; filename="example.txt"'
cd = ContentDisposition.parse(header)
print(cd.filename_utf8) # 'example.txt'
print(cd.disposition_type) # 'attachment'