{"record":{"id":"cfc087bb24c73fe7","repo":"windmill-labs/windmill","slug":"type-of-file-content-not-supported","errorCode":null,"errorMessage":"Type of file_content not supported","messagePattern":"Type of file_content not supported","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"python-client/wmill/wmill/client.py","lineNumber":987,"sourceCode":"        s3_obj = S3Object(s3=\"/path/to/my_file.txt\")\n\n        # for an in memory bytes array:\n        file_content = b'Hello Windmill!'\n        client.write_s3_file(s3_obj, file_content)\n\n        # for a file:\n        with open(\"my_file.txt\", \"rb\") as my_file:\n            client.write_s3_file(s3_obj, my_file)\n        '''\n        \"\"\"\n        s3object = parse_s3_object(s3object)\n        # httpx accepts either bytes or \"a bytes generator\" as content. If it's a BufferedReader, we need to convert it to a generator\n        if isinstance(file_content, BufferedReader):\n            content_payload = bytes_generator(file_content)\n        elif isinstance(file_content, bytes):\n            content_payload = file_content\n        else:\n            raise Exception(\"Type of file_content not supported\")\n\n        query_params = {}\n        if s3object is not None and s3object[\"s3\"] != \"\":\n            query_params[\"file_key\"] = s3object[\"s3\"]\n        if s3_resource_path is not None and s3_resource_path != \"\":\n            query_params[\"s3_resource_path\"] = s3_resource_path\n        if (\n            s3object is not None\n            and \"storage\" in s3object\n            and s3object[\"storage\"] is not None\n        ):\n            query_params[\"storage\"] = s3object[\"storage\"]\n        if content_type is not None:\n            query_params[\"content_type\"] = content_type\n        if content_disposition is not None:\n            query_params[\"content_disposition\"] = content_disposition\n\n        try:","sourceCodeStart":969,"sourceCodeEnd":1005,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/python-client/wmill/wmill/client.py#L969-L1005","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nwm.write_s3_file(s3obj, \"my file contents\")\n// after\nwm.write_s3_file(s3obj, \"my file contents\".encode(\"utf-8\"))","handlingStrategy":"validation","validationCode":"import io\nif not isinstance(file_content, (bytes, io.BufferedReader)):\n    raise TypeError(f\"file_content must be bytes or BufferedReader, got {type(file_content).__name__}\")","typeGuard":"def is_valid_s3_content(c: object) -> bool:\n    import io\n    return isinstance(c, (bytes, io.BufferedReader))","tryCatchPattern":"try:\n    wm.write_s3_file(s3obj, file_content)\nexcept Exception as e:\n    if \"Type of file_content not supported\" in str(e):\n        fixed = file_content.encode(\"utf-8\") if isinstance(file_content, str) else bytes(file_content)\n        wm.write_s3_file(s3obj, fixed)\n    else:\n        raise","preventionTips":["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"],"tags":["python","s3","type-error","input-validation"],"backgroundTag":"unsupported-argument-type","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}