# Buggy code
def send(self, x):
    iff, a, gw = x.route()
    if iff is None:
        iff = conf.iface
    sdto = (iff, self.type)
    self.outs.bind(sdto)
    sn = self.outs.getsockname()
    ll = lambda x: x
    if type(x) in conf.l3types:
        sdto = (iff, conf.l3types[type(x)])
    if sn[3] in conf.l2types:
        ll = lambda x: conf.l2types[sn[3]]() / x
    sx = raw(ll(x))
    try:
        self.outs.sendto(sx, sdto)
    except socket.error as msg:
        if msg.errno == 22 and len(sx) < conf.min_pkt_size:
            self.outs.send(sx + b"\x00" * (conf.min_pkt_size - len(sx)))
        elif conf.auto_fragment and msg.errno == 90:
            for p in x.fragment():
                self.outs.sendto(raw(ll(p)), sdto)
        else:
            raise
    x.sent_time = time.time()


# 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 send(self, x):
    iff = x.route()[0]
    if iff is None:
        iff = conf.iface
    sdto = (iff, self.type)
    self.outs.bind(sdto)
    sn = self.outs.getsockname()
    ll = lambda x: x
    if type(x) in conf.l3types:
        sdto = (iff, conf.l3types[type(x)])
    if sn[3] in conf.l2types:
        ll = lambda x: conf.l2types[sn[3]]() / x
    sx = raw(ll(x))
    try:
        self.outs.sendto(sx, sdto)
    except socket.error as msg:
        if msg.errno == 22 and len(sx) < conf.min_pkt_size:
            self.outs.send(sx + b"\x00" * (conf.min_pkt_size - len(sx)))
        elif conf.auto_fragment and msg.errno == 90:
            for p in x.fragment():
                self.outs.sendto(raw(ll(p)), sdto)
        else:
            raise
    x.sent_time = time.time()