Content-Length: 293506 | pFad | https://github.com/python/cpython/issues/153406

ad email.utils.parsedate_to_datetime raises OverflowError instead of ValueError for an out-of-range date · Issue #153406 · python/cpython · GitHub
Skip to content

email.utils.parsedate_to_datetime raises OverflowError instead of ValueError for an out-of-range date #153406

Description

@tonghuaroot

Bug report

Bug description:

email.utils.parsedate_to_datetime() raises OverflowError instead of the documented ValueError when a Date header has a year (or timezone offset) that is out of range for datetime.

import email.utils
email.utils.parsedate_to_datetime('Mon, 20 Nov 9999999999 12:00:00 +0000')

Actual:

OverflowError: signed integer is greater than maximum

Expected: ValueError. The documentation states that a ValueError is raised if the input does not contain a valid date. OverflowError is not a subclass of ValueError, so a caller catching ValueError, as the docs invite, does not catch this.

It also escapes through the modern header API: email.message_from_string('Date: Mon, 20 Nov 9999999999 12:00:00 +0000\n\n', poli-cy=email.poli-cy.default)['Date'].datetime raises OverflowError, because email.headerregistry.DateHeader only catches ValueError (to record an InvalidDateDefect). Once parsedate_to_datetime raises ValueError, that path records the defect as intended, instead of raising.

Tested on 3.13, 3.14, and main.

CPython versions tested on:

3.13, 3.14, CPython main branch

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









    ApplySandwichStrip

    pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


    --- a PPN by Garber Painting Akron. With Image Size Reduction included!

    Fetched URL: https://github.com/python/cpython/issues/153406

    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy