Python TypeError: send_arp_reply() got an unexpected keyword argument 'timeout' 解决方法
Python TypeError: send_arp_reply() got an unexpected keyword argument 'timeout' 解决方法
在使用 Python 编写网络扫描程序时,你可能会遇到以下错误:
return self.func(*args)
File "h.py", line 230, in save_button_click
save_records()
File "h.py", line 175, in save_records
active_hosts = scan_network(ifname)
File "h.py", line 168, in scan_network
response = send_arp_reply(ifname, timeout=1)
TypeError: send_arp_reply() got an unexpected keyword argument 'timeout'
这个错误通常是由于 send_arp_reply 函数的定义中没有包含 timeout 参数造成的。
解决方法
有两种解决方法:
-
将
send_arp_reply函数的定义中去掉timeout参数。
def send_arp_reply(ifname): ...
def scan_network(ifname): active_hosts = {} for i in range(1, 255): dst_ip = '192.168.197.' + str(i) send_arp_request(ifname, '192.168.197.1', get_mac_address(ifname), dst_ip) time.sleep(0.1) response = send_arp_reply(ifname) if response is not None: active_hosts[response['src_ip']] = response['src_mac'] return active_hosts
2. **将调用 `send_arp_reply` 函数时的 `timeout` 参数改为其他名称。**
```python
def send_arp_reply(ifname, **kwargs):
... # 使用 kwargs 接收所有参数
def scan_network(ifname):
active_hosts = {}
for i in range(1, 255):
dst_ip = '192.168.197.' + str(i)
send_arp_request(ifname, '192.168.197.1', get_mac_address(ifname), dst_ip)
time.sleep(0.1)
response = send_arp_reply(ifname, wait_time=1) # 将 timeout 改为 wait_time
if response is not None:
active_hosts[response['src_ip']] = response['src_mac']
return active_hosts
选择哪种方法取决于 send_arp_reply 函数的具体实现和你的需求。如果你不需要 timeout 参数,则可以选择第一种方法;如果你需要使用 timeout 参数,则可以选择第二种方法。
总结
通过修改 send_arp_reply 函数的定义或调用方式,可以解决 TypeError: send_arp_reply() got an unexpected keyword argument 'timeout' 错误。
原文地址: https://www.cveoy.top/t/topic/jm8j 著作权归作者所有。请勿转载和采集!