【发布时间】:2014-12-10 00:01:44
【问题描述】:
我尝试在 python 3.4 中使用的代码:
#!/usr/bin/python3
def get_mac_addr(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', ifname[:15]))
return ''.join(['%02x:' % ord(char) for char in info[18:24]])[:-1]
print (get_mac_addr('eth0'))
Error: struct.error: argument for 's' must be a bytes object
我看到这段代码在不使用 python3 时确实有效,但我的项目需要在 3 中使用它。我尝试比较问题:Struct.Error, Must Be a Bytes Object?,但我不知道如何将其应用于自己。
【问题讨论】:
标签: python networking