FujiwaraChoki/MoneyPrinterV2 · error · PostBridgeClientError

Post Bridge did not return a media_id and upload_url.

Error message

Post Bridge did not return a media_id and upload_url.

What it means

Raised by PostBridgeClient.upload_media when the media-creation response lacks media_id or upload_url. These two fields are required to know what to PUT the file bytes to, so the upload cannot proceed.

Source

Thrown at src/classes/PostBridge.py:119

        file_name = os.path.basename(file_path)
        mime_type = self._guess_mime_type(file_path)
        file_size = os.path.getsize(file_path)

        upload_response = self._request_json(
            "POST",
            f"{self.API_BASE}/media/create-upload-url",
            json={
                "name": file_name,
                "mime_type": mime_type,
                "size_bytes": file_size,
            },
        )

        media_id = upload_response.get("media_id")
        upload_url = upload_response.get("upload_url")

        if not media_id or not upload_url:
            raise PostBridgeClientError(
                "Post Bridge did not return a media_id and upload_url."
            )

        with open(file_path, "rb") as media_file:
            self._request(
                "PUT",
                upload_url,
                data=media_file,
                headers={"Content-Type": mime_type},
                timeout=600,
                expected_statuses={200, 201},
                use_default_headers=False,
            )

        return media_id

    def create_post(
        self,

View on GitHub (pinned to 5192af8eca)

Solutions

  1. Log the full upload_response to identify the actual payload (renamed fields vs error envelope)
  2. Update field extraction to match the current API (e.g. upload_response.get('id') as fallback)
  3. Verify the API token and account permissions for media uploads
  4. Handle a nested structure like upload_response['data']['media_id'] if the API wrapped the payload

Example fix

// before
media_id = upload_response.get("media_id")
upload_url = upload_response.get("upload_url")

// after
payload = upload_response.get("data", upload_response)
media_id = payload.get("media_id") or payload.get("id")
upload_url = payload.get("upload_url") or payload.get("uploadUrl")
if not media_id or not upload_url:
    raise PostBridgeClientError(f"Unexpected media payload: {upload_response!r}")
Defensive patterns

Strategy: type-guard

Type guard

def has_media_upload_fields(payload: dict) -> bool:
    data = payload.get("data", payload) if isinstance(payload, dict) else {}
    return bool(
        isinstance(data, dict)
        and (data.get("media_id") or data.get("id"))
        and (data.get("upload_url") or data.get("uploadUrl"))
    )

Try / catch

try:
    media_id = client.upload_media(path)
except PostBridgeClientError as exc:
    if "media_id and upload_url" in str(exc):
        logging.error("Token/permission or API version issue; check Post Bridge account")
    raise

Prevention

When it happens

Trigger: The create-media endpoint returns an error object or partial payload with 200 status; fields renamed by a newer API version (e.g. 'id' instead of 'media_id'); or an empty dict returned on quota/auth edge cases.

Common situations: API schema drift after a Post Bridge update, expired/invalid API token producing a soft error, or account lacking media-upload permission so the response contains an error envelope.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of FujiwaraChoki/MoneyPrinterV2@5192af8eca (2026-08-28). Data as JSON: /api/errors/fdd24784a4041371. Report an issue: GitHub.