# Buggy code
def _find_fld(self):
    """Returns the Field subclass to be used, depending on the Packet
    instance, or the default subclass.

    DEV: since the Packet instance is not provided, we have to use a hack
    to guess it. It should only be used if you cannot provide the current
    Packet instance (for example, because of the current Scapy API).

    If you have the current Packet instance, use ._find_fld_pkt_val() (if
    the value to set is also known) of ._find_fld_pkt() instead.

    """
    # Hack to preserve current Scapy API
    # See https://stackoverflow.com/a/7272464/3223422
    frame = inspect.currentframe().f_back.f_back
    while frame is not None:
        try:
            pkt = frame.f_locals["self"]
        except KeyError:
            pass
        else:
            if not pkt.default_fields:
                # Packet not initialized
                return self.dflt
            if isinstance(pkt, tuple(self.dflt.owners)):
                return self._find_fld_pkt(pkt)
        frame = frame.f_back
    return self.dflt


# Traceback (TypeError)
faucet@faucet:~$ sudo bash
root@faucet:~# python3
Python 3.6.8 (default, Jan 14 2019, 11:02:34)
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
from scapy.all import *
scapy.all.send(fuzz(ARP(pdst='127.0.0.1')))
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/scapy/compat.py", line 117, in raw
return bytes(x)
File "/usr/local/lib/python3.6/dist-packages/scapy/packet.py", line 441, in __bytes__
return self.build()
File "/usr/local/lib/python3.6/dist-packages/scapy/packet.py", line 556, in build
p = self.do_build()
File "/usr/local/lib/python3.6/dist-packages/scapy/packet.py", line 541, in do_build
pay = self.do_build_payload()
File "/usr/local/lib/python3.6/dist-packages/scapy/packet.py", line 528, in do_build_payload
return self.payload.do_build()
File "/usr/local/lib/python3.6/dist-packages/scapy/packet.py", line 538, in do_build
pkt = self.self_build()
File "/usr/local/lib/python3.6/dist-packages/scapy/packet.py", line 519, in self_build
p = f.addfield(self, p, val)
File "/usr/local/lib/python3.6/dist-packages/scapy/fields.py", line 134, in addfield
return s + struct.pack(self.fmt, self.i2m(pkt, val))
File "/usr/local/lib/python3.6/dist-packages/scapy/fields.py", line 1314, in i2m
f = fld.i2len(pkt, fval)
File "/usr/local/lib/python3.6/dist-packages/scapy/fields.py", line 343, in i2len
return self._find_fld_pkt_val(pkt, val).i2len(pkt, val)
File "/usr/local/lib/python3.6/dist-packages/scapy/fields.py", line 884, in i2len
return len(i)
TypeError: object of type 'NoneType' has no len()

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/dist-packages/scapy/sendrecv.py", line 314, in send
realtime=realtime, return_packets=return_packets)
File "/usr/local/lib/python3.6/dist-packages/scapy/sendrecv.py", line 287, in __gen_send
s.send(p)
File "/usr/local/lib/python3.6/dist-packages/scapy/arch/linux.py", line 533, in send
sx = raw(ll(x))
File "/usr/local/lib/python3.6/dist-packages/scapy/compat.py", line 119, in raw
return bytes(x, encoding="utf8")
TypeError: encoding without a string argument

# Fixed code
def _find_fld(self):
    """Returns the Field subclass to be used, depending on the Packet
    instance, or the default subclass.

    DEV: since the Packet instance is not provided, we have to use a hack
    to guess it. It should only be used if you cannot provide the current
    Packet instance (for example, because of the current Scapy API).

    If you have the current Packet instance, use ._find_fld_pkt_val() (if
    the value to set is also known) of ._find_fld_pkt() instead.

    """
    # Hack to preserve current Scapy API
    # See https://stackoverflow.com/a/7272464/3223422
    frame = inspect.currentframe().f_back.f_back
    while frame is not None:
        try:
            pkt = frame.f_locals["self"]
        except KeyError:
            pass
        else:
            if isinstance(pkt, tuple(self.dflt.owners)):
                if not pkt.default_fields:
                    # Packet not initialized
                    return self.dflt
                return self._find_fld_pkt(pkt)
        frame = frame.f_back
    return self.dflt