Repository navigation
shutil.copyfile does not raise SpecialFileError for socket files #81881
Description
Activity
Currently shutil.copyfile only raises SpecialFileError for named pipes. When trying to use the function to copy a socket file, the exception raised depends on the platform, for example:
macOS: "[Errno 102] Operation not supported on socket: '/Users/guido/src/mypy/dmypy.sock'"
HP-UX: "[Errno 223] Operation not supported: 'example/foo'"
Solaris: "[Errno 122] Operation not supported on transport endpoint: 'example/foo'"
AIX: "[Errno 64] Operation not supported on socket: '../../example/foo'"
Linux: "[Errno 6] No such device or address: 'example/foo'"This can be reproduced like:
import os import shutil import socket import tempfile d = tempfile.mkdtemp() src = os.path.join(d, "src") dest = os.path.join(d, "dest") sock = socket.socket(socket.AF_UNIX) sock.bind(src) shutil.copyfile(src, dest)
Making shutil.copyfile raise SpecialFileError for socket files would improve the interface of this function since the same class of error could be ignored. This is mostly useful with shutil.copytree, which defaults to copyfile for its copy function.
- added3.7 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Jul 29, 2019 See also: the comment from
:Line 245 in e1b9002
# XXX What about other special files? (sockets, devices...) XXX What about other special files? (sockets, devices...)
This issue is being filed after coming up in pip's tracker here (in a comment by Guido): pypa/pip#5306 (comment)
- added3.9 (EOL)end of lifeend of life3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixesand removed3.7 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life
on Dec 11, 2021 - removed3.11only security fixesonly security fixes3.10 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of life
on Dec 14, 2025 - added a commit that references this issue
on Jun 30, 2026 - added a commit that references this issue
on Jul 1, 2026
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:
bugs.python.org fields:
Linked PRs
SpecialFileErrorfor sockets and devices inshutil.copyfile#142693