windmill-labs/windmill · error · Exception
Type of file_content not supported
Error message
Type of file_content not supported
What it means
write_s3_file only accepts file_content that is raw bytes (bytes) or a BufferedReader (a file opened in binary mode), because httpx request content must be bytes or a bytes generator. Any other type (str, io.StringIO, io.BytesIO, text-mode file objects, etc.) is rejected with this exception before any network call is made.
Source
Thrown at python-client/wmill/wmill/client.py:987
s3_obj = S3Object(s3="/path/to/my_file.txt")
# for an in memory bytes array:
file_content = b'Hello Windmill!'
client.write_s3_file(s3_obj, file_content)
# for a file:
with open("my_file.txt", "rb") as my_file:
client.write_s3_file(s3_obj, my_file)
'''
"""
s3object = parse_s3_object(s3object)
# httpx accepts either bytes or "a bytes generator" as content. If it's a BufferedReader, we need to convert it to a generator
if isinstance(file_content, BufferedReader):
content_payload = bytes_generator(file_content)
elif isinstance(file_content, bytes):
content_payload = file_content
else:
raise Exception("Type of file_content not supported")
query_params = {}
if s3object is not None and s3object["s3"] != "":
query_params["file_key"] = s3object["s3"]
if s3_resource_path is not None and s3_resource_path != "":
query_params["s3_resource_path"] = s3_resource_path
if (
s3object is not None
and "storage" in s3object
and s3object["storage"] is not None
):
query_params["storage"] = s3object["storage"]
if content_type is not None:
query_params["content_type"] = content_type
if content_disposition is not None:
query_params["content_disposition"] = content_disposition
try:View on GitHub (pinned to e474e8803c)
Solutions
- Encode strings to bytes: file_content.encode('utf-8')
- Open files in binary mode: open(path, 'rb')
- For in-memory buffers pass buf.getvalue() bytes or io.BytesIO(...).read()
- Check isinstance(file_content, (bytes, io.BufferedReader)) before calling
Example fix
// before
wm.write_s3_file(s3obj, "my file contents")
// after
wm.write_s3_file(s3obj, "my file contents".encode("utf-8")) Defensive patterns
Strategy: validation
Validate before calling
import io
if not isinstance(file_content, (bytes, io.BufferedReader)):
raise TypeError(f"file_content must be bytes or BufferedReader, got {type(file_content).__name__}") Type guard
def is_valid_s3_content(c: object) -> bool:
import io
return isinstance(c, (bytes, io.BufferedReader)) Try / catch
try:
wm.write_s3_file(s3obj, file_content)
except Exception as e:
if "Type of file_content not supported" in str(e):
fixed = file_content.encode("utf-8") if isinstance(file_content, str) else bytes(file_content)
wm.write_s3_file(s3obj, fixed)
else:
raise Prevention
- Always open files with mode='rb' for binary upload
- Encode str data with .encode('utf-8') before upload
- Wrap write_s3_file in a helper that normalizes str/bytes input
When it happens
Trigger: Calling wm.write_s3_file with file_content as a str, an io.StringIO, an io.BytesIO, a text-mode file object, or json.dumps() output without .encode(), e.g. wm.write_s3_file(s3obj, 'hello') where 'hello' is a str.
Common situations: Forgetting 'rb' mode when opening files (open(path) instead of open(path, 'rb')), passing string data without encoding, or passing pandas/numpy/buffer objects directly.
Related errors
- Invalid s3 object {s3_object!r}: expected an s3://<storage>/
- Could not generate DuckDB S3 connection settings from the pr
- Could not generate Polars S3 connection settings from the pr
- Could not generate Boto3 S3 connection settings from the pro
- Invalid s3 object URI {s3_object!r}: expected s3://<storage>
AI-assisted analysis of windmill-labs/windmill@e474e8803c (2026-09-03).
Data as JSON: /api/errors/cfc087bb24c73fe7.
Report an issue: GitHub.