python 'socket' has no attribute 'CAN_J1939'

86 views Asked by At

just making a pretty straightforward J1939 reader with the socket library:

import socket

with socket.socket(socket.PF_CAN, socket.SOCK_DGRAM, socket.CAN_J1939) as s:
    s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
    addr = "can3", socket.J1939_NO_NAME, socket.J1939_NO_PGN, socket.J1939_NO_ADDR
    s.bind(addr)

    while True:
        data, addr = s.recvfrom(128)
        print(f'{addr[3]:02x} {addr[2]:05x}')

        for j in range(len(data)):
            if j % 8 == 0 and j != 0:
                print(f'\n{j:05x}    ')
            print(f'{j:02x}')
        print('\n')

running this give me this error:

AttributeError: module 'socket' has no attribute 'CAN_J1939'

i'm not sure why the heck this error is firing. i have can-utils installed and a couple other J1939 libs when i wrote the Buildroot, so i don't know why this is popping up. plus, i'm running v3.10 on the SoC and the CAN_J1939 has be available since v3.5. :P don't even know how to troubleshoot this one... O_o

0

There are 0 answers