GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — _socket: `socket.sethostname()` reports a failed buffer export as an OS error, raising `SystemError` · Issue #161665 · python/cpython

_socket: socket.sethostname() reports a failed buffer export as an OS error, raising SystemError #161665

New issue
Copy link
New issue
Copy link
Open
Open
_socket: socket.sethostname() reports a failed buffer export as an OS error, raising SystemError#161665
Copy link
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtopic-socketRelated to the socket, socketserver and selectors modulesRelated to the socket, socketserver and selectors modulestype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@theosotr
theosotr
opened on Nov 9, 2026
Issue body actions

Bug report

Summary

socket.sethostname() accepts a bytes subclass, and if getting a buffer from that object fails, the error is not reported. Instead SystemError is returned to caller.

SystemError: <class 'OSError'> returned a result with an exception set

Reproducer

import os
import socket

class B(bytes):
    def __buffer__(self, flags):
        raise KeyError("boom")

try:
    os.stat("/nonexistent")
except OSError:
    pass

socket.sethostname(B(b"h"))
Traceback (most recent call last):
  File "min.py", line 23, in <module>
    socket.sethostname(B(b"h"))
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^
SystemError: <class 'OSError'> returned a result with an exception set

CPython versions tested on:

3.15

Operating systems tested on:

Linux

Linked PRs

  • gh-161665: Propagate buffer errors in socket.sethostname() #161684

Activity

  1. theosotr
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Nov 9, 2026
  2. picnixz
    added
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    topic-socketRelated to the socket, socketserver and selectors modulesRelated to the socket, socketserver and selectors modules
    on Nov 9, 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

    extension-modulesC modules in the Modules dirC modules in the Modules dirtopic-socketRelated to the socket, socketserver and selectors modulesRelated to the socket, socketserver and selectors modulestype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.