Skip to content

errno and strerror attributes incorrectly set on socket errors wrapped by urllib #50720

Closed

Description

@ezio-melotti
BPO 6471
Nosy @birkenfeld, @amauryfa, @orsenthil, @ezio-melotti, @bitdancer, @cjerdonek, @iritkatriel
Files
  • keeperrdata.patch: patch to retain errno and strerror
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2009-07-12.20:54:33.896>
    labels = ['type-bug', 'library', '3.9', '3.10', '3.11']
    title = 'errno and strerror attributes incorrectly set on socket errors wrapped by urllib'
    updated_at = <Date 2021-11-30.20:20:38.331>
    user = 'https://github.com/ezio-melotti'

    bugs.python.org fields:

    activity = <Date 2021-11-30.20:20:38.331>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2009-07-12.20:54:33.896>
    creator = 'ezio.melotti'
    dependencies = []
    files = ['26559']
    hgrepos = []
    issue_num = 6471
    keywords = ['patch']
    message_count = 9.0
    messages = ['90458', '90462', '90466', '100178', '166705', '167330', '170710', '170723', '407399']
    nosy_count = 9.0
    nosy_names = ['georg.brandl', 'amaury.forgeotdarc', 'orsenthil', 'ezio.melotti', 'r.david.murray', 'chris.jerdonek', 'catherine', 'denkoren', 'iritkatriel']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'needs patch'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue6471'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    Linked PRs

    Activity

    1. iritkatriel commented on Nov 30, 2021

      @iritkatriel
      Member

      Reproduced on 3.11:

      >>> from urllib.request import urlopen
      >>> try:
      ...     urlopen('http://www.pythonfoobarbaz.org')
      ... except Exception as exc:
      ...     err = exc
      ...     print('err:', err)
      ...     print('repr(err):', repr(err))
      ...     print('err.errno:', err.errno)
      ...     print('err.strerror:', err.strerror)
      ...     print('err.reason:', err.reason)
      ...     print('err.reason.errno:', err.reason.errno)
      ...     print('err.reason.strerror:', err.reason.strerror)
      ... 
      err: <urlopen error [Errno 8] nodename nor servname provided, or not known>
      repr(err): URLError(gaierror(8, 'nodename nor servname provided, or not known'))
      err.errno: None
      err.strerror: None
      err.reason: [Errno 8] nodename nor servname provided, or not known
      err.reason.errno: 8
      err.reason.strerror: nodename nor servname provided, or not known
    2. transferred this issue fromon Apr 10, 2022
    3. added
      3.12only security fixes
      and removed on Mar 1, 2023
    4. vasiliyk commented on Oct 21, 2026

      @vasiliyk
      Contributor

      Still reproduces on 3.16.0a1+dev:

      >>> from urllib.request import urlopen
      >>> try:
      ...     urlopen('http://www.pythonfoobarbaz.org')
      ... except Exception as exc:
      ...     err = exc
      ...     print('err:', err)
      ...     print('repr(err):', repr(err))
      ...     print('err.errno:', err.errno)
      ...     print('err.strerror:', err.strerror)
      ...     print('err.reason:', err.reason)
      ...     print('err.reason.errno:', err.reason.errno)
      ...     print('err.reason.strerror:', err.reason.strerror)
      ... 
      err: <urlopen error [Errno 8] nodename nor servname provided, or not known>
      repr(err): URLError(gaierror(8, 'nodename nor servname provided, or not known'))
      err.errno: None
      err.strerror: None
      err.reason: [Errno 8] nodename nor servname provided, or not known
      err.reason.errno: 8
      err.reason.strerror: nodename nor servname provided, or not known

      URLError.__init__ sets only args and reason, so the OSError attributes are never set.

      Following the original patch:

      • in URLError.__init__, if reason is an OSError, copy its errno and strerror.
      • args, str() and repr() do not change, so the backward-compatibility concern does not apply.

      I can open a PR with tests if this approach is fine.

    5. orsenthil commented on Oct 29, 2026

      @orsenthil
      Member

      @vasiliyk, please create the patch with the approach.

    6. vasiliyk commented on Oct 30, 2026

      @vasiliyk
      Contributor

      @orsenthil The PR is up - #160938. I added a a versionchanged note for 3.16 in urllib.error doc.

    7. moved this from Todo to In Progress in Urllib issueson Oct 31, 2026
    8. added a commit that references this issue on Oct 31, 2026
    9. added
      3.16new features, bugs and security fixes
      and removed
      3.11only security fixes
      3.12only security fixes
      on Oct 31, 2026
    10. orsenthil commented on Oct 31, 2026

      @orsenthil
      Member

      Thanks for this patch. This shouldn't be backported as there is subtle scenario wherein if an old code was checking e.errno is None previously to fall back on OSError, it will break and will need a change.

    11. moved this from In Progress to Done in Urllib issueson Oct 31, 2026
    12. closed this as completedby moving to Done in Urllib issueson Oct 31, 2026
    13. added 2 commits that reference this issue on Oct 31, 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

      3.16new features, bugs and security fixesstdlibStandard 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