Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Description
Bug report
Bug description:
When trying to usesocket.CAN_RAW_ERR_FILTER on a Debian bookworm system, running Python 3.11, anAttributeError is raised. This is because the value is no longer defined insocket.py/_socket.
I have also tested in Python 3.13.1, and the issue is still present there.
Typical usage of the value:
importsocketsock=socket.socket(socket.AF_CAN,socket.SOCK_RAW|socket.SOCK_NONBLOCK,socket.CAN_RAW)sock.bind((interface_name,))sock.setsockopt(socket.SOL_CAN_RAW,socket.CAN_RAW_ERR_FILTER,socket.CAN_ERR_MASK)
Minimized reproduction:
importsocketprint(socket.CAN_RAW_ERR_FILTER)
Actual output:
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):
2Investigating the issue, it seems to have been introduced in Python 3.11 by the following PR:#30066
In this PR, adding theCAN_RAW_ERR_FILTER value tosocket was made conditional on definingCAN_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 theCAN_RAW_ERR_FILTER value is coming fromlinux/can/raw.h where is it defined as anenum value. Thus it will not be used by the C/C++ preprocessor to evaluate the#ifdef CAN_RAW_ERR_FILTER inModules/socketmodule.c.
Excerpt of relevantraw.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) */};
CPython versions tested on:
3.11, 3.13
Operating systems tested on:
Linux