【发布时间】:2018-08-15 03:05:39
【问题描述】:
【问题讨论】:
-
确保您在扩展中选择了合适的解释器环境,以便它找到模块。
标签: python visual-studio-code scapy
【问题讨论】:
标签: python visual-studio-code scapy
我在 VS Code 中的 Scapy 代码遇到了完全相同的问题。我认为这与 pylint 的工作方式有关。
当您from scapy.all import IP 时,Python 会加载 scapy/all.py,其中包括 from scapy.layers.all import * 行。 scapy/layers/all.py 包含此代码:
for _l in conf.load_layers:
log_loading.debug("Loading layer %s" % _l)
try:
load_layer(_l, globals_dict=globals(), symb_list=__all__)
except Exception as e:
log.warning("can't import layer %s: %s", _l, e)
conf.load_layers 结束于scapy/config.py:
load_layers = ['bluetooth', 'bluetooth4LE', 'dhcp', 'dhcp6', 'dns',
'dot11', 'dot15d4', 'eap', 'gprs', 'hsrp', 'inet',
'inet6', 'ipsec', 'ir', 'isakmp', 'l2', 'l2tp',
'llmnr', 'lltd', 'mgcp', 'mobileip', 'netbios',
'netflow', 'ntp', 'ppp', 'pptp', 'radius', 'rip',
'rtp', 'sctp', 'sixlowpan', 'skinny', 'smb', 'snmp',
'tftp', 'vrrp', 'vxlan', 'x509', 'zigbee']
我怀疑 pylint 没有正确遵循这些导入。
我已经尝试了relevant GitHub issue 中建议的解决方法,但它们似乎没有为 Scapy 解决任何问题。 Pylint 最终为 Numpy 中的问题添加了 specific workarounds - 没有人为 Scapy 这样做。
您可以通过直接从 Python 文件顶部的相关层导入 IP 类来解决这些问题:
from scapy.layers.inet import IP, UDP, TCP, ICMP
瞧!没有更多关于这些进口的 pylint 投诉。
【讨论】: