You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
socket.CAN_RAW_ERR_FILTER is not defined in Python 3.11 and later #129719
When trying to use socket.CAN_RAW_ERR_FILTER on a Debian bookworm system, running Python 3.11, an AttributeError is raised. This is because the value is no longer defined in socket.py/_socket.
I have also tested in Python 3.13.1, and the issue is still present there.
Traceback (most recent call last):
File "<python-input-1>", line 1, in <module>
print(socket.CAN_RAW_ERR_FILTER)
^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'socket' has no attribute 'CAN_RAW_ERR_FILTER'. Did you mean: 'CAN_RAW_FILTER'?
Expected output (taken from Python 3.10.12):
2
Investigating the issue, it seems to have been introduced in Python 3.11 by the following PR: #30066
In this PR, adding the CAN_RAW_ERR_FILTER value to socket was made conditional on defining CAN_RAW_ERR_FILTER during compilation. However, no change was made to actually define the value, thus it is never compiled for compatible systems.
Note that the CAN_RAW_ERR_FILTER value is coming from linux/can/raw.h where is it defined as an enum value. Thus it will not be used by the C/C++ preprocessor to evaluate the #ifdef CAN_RAW_ERR_FILTER in Modules/socketmodule.c.
Excerpt of relevant raw.h file from Debian Bookworm:
/* for socket options affecting the socket (not the global system) */enum {
CAN_RAW_FILTER=1, /* set 0 .. n can_filter(s) */CAN_RAW_ERR_FILTER, /* set filter for error frames */CAN_RAW_LOOPBACK, /* local loopback (default:on) */CAN_RAW_RECV_OWN_MSGS, /* receive my own msgs (default:off) */CAN_RAW_FD_FRAMES, /* allow CAN FD frames (default:off) */CAN_RAW_JOIN_FILTERS, /* all filters must match to trigger */CAN_RAW_XL_FRAMES, /* allow CAN XL frames (default:off) */
};
Activity
pythongh-129719: Restore missing socket.CAN_RAW_ERR_FILTER on Linux
pythongh-129719: Restore missing socket.CAN_RAW_ERR_FILTER on Linux
pythongh-129719: Restore missing socket.CAN_RAW_ERR_FILTER on Linux
pythongh-129719: Restore missing socket.CAN_RAW_ERR_FILTER on Linux
jbogers commentedon Feb 6, 2025
I've tried to make a PR with a fix (#129721). This is my first time contributing, so I hope I've correctly followed the required procedures.
gh-129719: Restore missing `socket.CAN_RAW_ERR_FILTER` on Linux (#129721
pythongh-129719: Restore missing `socket.CAN_RAW_ERR_FILTER` on Linux (…
[3.13] gh-129719: Restore missing `socket.CAN_RAW_ERR_FILTER` on Linux (