I'm building a sniffing tool using python-3.7 and I got that error when I was trying to use the scapy_http module.
It works fine in python-2.x. The object type is packet[scapy.Raw].load
Code:
#!usr/bin/env python
import scapy.all as scapy
from scapy.layers import http
def sniff(interface):
scapy.sniff(iface=interface, store=False, prn=process_sniffed_packet)
#store=Flase(does not store the output in memory)
#prn= call another function after one packet or any data is sniffed is sniffed
def process_sniffed_packet(packet):
if packet.haslayer(http.HTTPRequest):
if packet.haslayer(scapy.Raw):
load = packet[scapy.Raw].load
if "username" in load:
print(load)
sniff("eth0")
ERROR:
File "packet_sniffer.py", line 16, in <module>
sniff("eth0")
File "packet_sniffer.py", line 6, in sniff
scapy.sniff(iface=interface, store=False, prn=process_sniffed_packet)
File "/usr/local/lib/python3.8/site-packages/scapy/sendrecv.py", line 1036, in sniff
sniffer._run(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/scapy/sendrecv.py", line 989, in _run
session.on_packet_received(p)
File "/usr/local/lib/python3.8/site-packages/scapy/sessions.py", line 82, in on_packet_received
result = self.prn(pkt)
File "packet_sniffer.py", line 14, in process_sniffed_packet
if "username" in load:
****TypeError: a bytes-like object is required, not 'str'****