我目前正在学习 python,来自 java,并且偶然发现了一个我找不到答案的错误。我在 Windows 10 上使用的是最新的 python 版本,尽管我认为我遵循的教程是针对 Linux 的……希望您仍然可以帮助我。这是我的类(class)代码:
def main():
connection = socket.socket(socket.AF_INET, socket.SOCK_RAW,
socket.IPPROTO_IP)
#mainloop
raw_data, addr = connection.recvfrom(65536)
dest_mac, src_mac, eth_proto, data = ethernet_frame(raw_data)
print('\nEthernet Frame:')
print('Destination: {}, Source: {}, Protocol: {}'.format(dest_mac,
src_mac, eth_proto))
#unpack ethernet frame
def ethernet_frame(data):
dest_mac, src_mac, proto = struct.unpack('! 6s 6s H', data[:14])
return get_mac_addr(dest_mac), get_mac_addr(src_mac),
socket.htons(proto), data[14:]
#format MAC adress
def get_mac_addr(bytes_addr):
bytes_str = map('{:02x}'.format, bytes_addr)
return ':'.join(bytes_str).upper()
main()
执行时我收到以下错误:
OSError: [WinError 10022] An invalid argument was supplied
在“connection.recvfrom(65536)”行中。
这是 Windows 特定的错误吗?
最佳答案
套接字在绑定(bind)或发送数据之前没有地址。在使用 connection.bind((YOUR_IP, PORT))
调用 connection.recvfrom(65536)
之前绑定(bind)套接字。
关于python - 操作系统错误 : [WinError 10022] An invalid argument was supplied - Windows 10 Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43330897/