Skip to content

Type for requests.exceptions.JSONDecodeError is missing attributes #15167

@jceresini

Description

@jceresini

Example python code:

import requests
from requests.exceptions import JSONDecodeError

try:
    # Intentionally a url that does not return json
    requests.get("https://www.google.com").json()
except JSONDecodeError as exc:
    d = exc.doc
    print("Failed to decode json. Got:", d[:10])

Example output from above code. Requests behaves differently if simplejson is installed, so I'm including output with and without:

$ uv run --with "requests==2.32.5" --with "types-requests==2.32.4.20250913" repro.py 
Failed to decode json. Got: <!doctype 

$ uv run --with "requests==2.32.5" --with "types-requests==2.32.4.20250913" --with "simplejson" repro.py 
Failed to decode json. Got: <!doctype 

And here's the mypy error, again with and without simplejson:

$ uv run --with "requests==2.32.5" --with "types-requests==2.32.4.20250913" --with "mypy" mypy repro.py 
repro.py:7: error: "JSONDecodeError" has no attribute "doc"  [attr-defined]
Found 1 error in 1 file (checked 1 source file)

$ uv run --with "requests==2.32.5" --with "types-requests==2.32.4.20250913" --with "mypy" mypy repro.py 
repro.py:7: error: "JSONDecodeError" has no attribute "doc"  [attr-defined]
Found 1 error in 1 file (checked 1 source file)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions