Skip to content

PathLike upload tuples fail with an opaque connection error #196

Description

@danielgaskins

What happened?

A bare Path works as an upload, but the tuple form accepted by FileTypes does not:

from pathlib import Path

client.sessions.uploads.create(
    "session-id",
    file=("custom.md", Path("README.md"), "text/markdown"),
)

On current main at 5f5274b, this raises:

APIConnectionError: Connection error.

The underlying cause is:

AttributeError: 'PosixPath' object has no attribute 'read'

The same path is shared by certificate, extension, and session uploads.

Why it happens

is_file_content() treats every tuple as terminal file content. That means _transform_file() returns the tuple unchanged before its tuple-handling branch can read the PathLike value inside it. HTTPX later receives the raw Path and tries to call .read() on it.

Expected behavior

A PathLike inside any supported upload tuple should be read just like a bare Path, while preserving the custom filename, content type, and optional headers.

I have a small fix ready that keeps tuples separate from direct file content and adds sync and async coverage for all three supported tuple shapes.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions