struct.error: для байтового формата требуется -128 <= число <= 127 - PullRequest
0 голосов
/ 02 марта 2020

Я хотел создать WOL на сайте для удаленного включения моего P C, но я не понимаю свою ошибку.

def wake_on_lan(macaddress):
    """ Switches on remote computers using WOL. """
    if len(macaddress) == 12:
        pass
    elif len(macaddress) == 12 + 5:
        sep = macaddress[2]
        macaddress = macaddress.replace(sep, '')
    else:
        raise ValueError('Incorrect MAC address format')
    data = ''.join(['FFFFFFFFFFFF', macaddress * 20])
    send_data = ''
    for i in range(0, len(data), 2):
        send_data = b"".join([send_data,
                                struct.pack('B', int(data[i: i + 2], 16))])

    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
    sock.sendto(send_data, ('<broadcast>', 7))
struct.error
struct.error: byte format requires -128 <= number <= 127

Traceback (most recent call last)
File "/home/pi/Monsite/Monsite/run.py", line 45, in decorated
return f(*args, **kwargs)
File "/home/pi/Monsite/Monsite/run.py", line 112, in wakeup
wake_on_lan('**:**:**:**:**')
File "/home/pi/Monsite/Monsite/run.py", line 30, in wake_on_lan
struct.pack('b', int(data[i: i + 2], 16))])
struct.error: byte format requires -128 <= number <= 127
...