Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/assets/badges/package.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 15 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ jobs:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v4

- name: Setup Python for dependency audit
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v5
with:
python-version: "3.11"

- name: Install dependency auditor
run: |
python -m venv "$RUNNER_TEMP/pip-audit"
"$RUNNER_TEMP/pip-audit/bin/python" -m pip install --upgrade pip "setuptools>=84.1.0"
"$RUNNER_TEMP/pip-audit/bin/python" -m pip install pip-audit "filelock>=4.2.1"

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v5
with:
Expand All @@ -28,7 +39,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip "setuptools>=83.0.0"
python -m pip install requests pylint isort pip-audit
python -m pip install requests pylint isort
python -m pip install -e .

- name: Lint with Pylint
Expand All @@ -43,7 +54,9 @@ jobs:
run: python -m unittest discover tests/

- name: Dependency audit
run: pip-audit
run: |
"$RUNNER_TEMP/pip-audit/bin/pip-audit" --path "$(python -c 'import sysconfig; print(sysconfig.get_path("purelib"))')"
"$RUNNER_TEMP/pip-audit/bin/pip-audit"

- name: Dependency review
if: github.event_name == 'pull_request'
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
This project follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.6.1] - 2026-11-13

### Fixed
- Preserve API error details when the response has no top-level message.

## [3.6.0] - 2026-08-27

### Added
Expand Down
2 changes: 1 addition & 1 deletion mercadopago/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Config:

def __init__(self):
"""Builds version-dependent values (user_agent, tracking_id)."""
self.__version = "3.6.0"
self.__version = "3.6.1"
self.__user_agent = "MercadoPago Python SDK v" + self.__version
self.__product_id = "bc32bpftrpp001u8nhlg"
self.__tracking_id = "platform:" + platform.python_version()
Expand Down
25 changes: 19 additions & 6 deletions mercadopago/errors/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
per HTTP status code.
"""

import json


class MercadoPagoError(Exception):
"""Base exception for all MercadoPago API errors.
Expand All @@ -15,18 +17,29 @@ class MercadoPagoError(Exception):

Attributes:
status_code: HTTP status code (e.g. 400, 401, 500).
message: Human-readable error summary from the API.
error: Machine-readable error code (e.g. ``"unauthorized"``).
message: API message, or serialized response body if absent.
error: API message, or serialized response body if absent.
causes: List of detailed cause dicts returned by the API.
request_id: ``x-request-id`` header for support diagnosis.
"""

def __init__(self, status_code, response_body):
self.status_code = status_code
self.response = response_body or {}
self.message = self.response.get("message", "")
self.error = self.response.get("error", "")
self.causes = self.response.get("cause", [])
self.response = response_body if response_body is not None else {}
body = self.response if isinstance(self.response, dict) else {}
message = body.get("message")
if isinstance(message, str) and message.strip():
error_value = message
else:
try:
serialized_body = json.dumps(self.response, ensure_ascii=False)
error_value = serialized_body if serialized_body != "{}" else ""
except (TypeError, ValueError, OverflowError, RecursionError):
error_value = ""
error_value = error_value or f"HTTP {status_code or 0}"
self.message = error_value
self.error = error_value
self.causes = body.get("cause", [])
self.request_id = None # set by MPResponse if x-request-id header is available
super().__init__(f"[{status_code}] {self.message or self.error}")

Expand Down
8 changes: 6 additions & 2 deletions mercadopago/errors/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,14 @@ def is_success(self):

@property
def error_message(self):
"""Human-readable error message from the API body, or empty string."""
"""API message or a useful error fallback for unsuccessful responses."""
body = self.get("response") or {}
if isinstance(body, dict):
return body.get("message", "")
message = body.get("message", "")
if isinstance(message, str) and message.strip():
return message
if not self.is_success:
return build_error(self.status_code, body).error
return ""

@property
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "mercadopago"
version = "3.6.0"
version = "3.6.1"
authors = [
{name = "Mercado Pago", email = "mp_sdk@mercadopago.com"}
]
Expand Down
Loading