Skip to content

IPv6Network.next_network() raises the wrong error when addresses run out #156680

Description

@fedonman

Bug description:

_BaseNetwork.next_network() guards address-space exhaustion with except OverflowError, which only the IPv4 path raises, so on IPv6 the internal ValueError from _string_from_ip_int() escapes instead.

from ipaddress import IPv4Network, IPv6Network

for net in (IPv4Network('255.255.255.0/24'),
            IPv6Network('ffff:ffff:ffff:ffff:ffff:ffff:ffff:0/112')):
    try:
        net.next_network()
    except ValueError as e:
        print(f"{net}: {e}")

Output:

255.255.255.0/24: out of address space, cannot make another /24 network
ffff:ffff:ffff:ffff:ffff:ffff:ffff:0/112: IPv6 address is too large

Expected: out of address space, cannot make another /112 network, the message Doc/library/ipaddress.rst gives for next_network().

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Activity

  1. 777GE90 commented on Aug 30, 2026

    @777GE90
    Contributor

    Hopefully should be resolved under c6b1d1a

  2. added
    type-bugAn unexpected behavior, bug, or error
    stdlibStandard Library Python modules in the Lib/ directory
    on Aug 31, 2026
  3. added a commit that references this issue on Sep 10, 2026
  4. orsenthil commented on Sep 10, 2026

    @orsenthil
    Member

    Reopening this to update a doc string of the module.

  5. added a commit that references this issue on Sep 10, 2026
  6. added a commit that references this issue on Sep 12, 2026
  7. added a commit that references this issue on Sep 14, 2026
  8. added a commit that references this issue on Sep 18, 2026
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

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions