vscode import error: from scapy.all import IP

匿名 (未验证) 提交于 2019-12-03 01:09:02

问题:

vscode said can't find IP in scapy.all

but from terminal, i can import it:

could somebody tell my why?

回答1:

I get exactly the same issue with my Scapy code in VS Code. I think it's to do with the way pylint is working.

When you from scapy.all import IP, Python loads scapy/all.py, which includes the line from scapy.layers.all import *. scapy/layers/all.py includes this code:

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 is over in 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'] 

I suspect that pylint doesn't follow those imports correctly.

I've tried the workarounds suggested in the relevant GitHub issue, but they don't seem to fix anything for Scapy. Pylint eventually added specific workarounds for the issues in Numpy - and no-one has done that for Scapy.

You can work around these issues by directly importing the IP class from the relevant layer at the top of your Python file:

from scapy.layers.inet import IP, UDP, TCP, ICMP 

Et voila! No more pylint complaints about those imports.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!