Skip to content

Fix iCloud upload failure: make NamedFileStream pass requests' file c… - #14

Open
Micha2 wants to merge 1 commit into
IsmaeelAkram:masterfrom
Micha2:fix/upload
Open

Fix iCloud upload failure: make NamedFileStream pass requests' file c…#14
Micha2 wants to merge 1 commit into
IsmaeelAkram:masterfrom
Micha2:fix/upload

Conversation

@Micha2

@Micha2 Micha2 commented Jun 23, 2026

Copy link
Copy Markdown

NamedFileStream exposed read() only through getattr. requests' _encode_files detects readable file objects with
isinstance(fp, _SupportsRead), a runtime_checkable Protocol that, on Python 3.12+, inspects the class rather than going through getattr. The wrapper therefore failed the check, so requests treated it as raw data and passed the object straight to urllib3's body.write(), raising "a bytes-like object is required, not 'NamedFileStream'".

Define read() explicitly so the stream satisfies the protocol check, while keeping the wrapper so the uploaded file gets the correct basename instead of the full local mirror path.

…heck

NamedFileStream exposed read() only through __getattr__. requests'
_encode_files detects readable file objects with
isinstance(fp, _SupportsRead), a runtime_checkable Protocol that, on
Python 3.12+, inspects the class rather than going through __getattr__.
The wrapper therefore failed the check, so requests treated it as raw
data and passed the object straight to urllib3's body.write(), raising
"a bytes-like object is required, not 'NamedFileStream'".

Define read() explicitly so the stream satisfies the protocol check,
while keeping the wrapper so the uploaded file gets the correct basename
instead of the full local mirror path.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant