invernizzi / scapy-http

Support for HTTP in Scapy
Other
301 stars 77 forks source link

fixes #26 "TypeError: a bytes-like object is required, not str" #27

Open sim0nx opened 7 years ago

sim0nx commented 7 years ago

This PR fixes #26

arslanmughal99 commented 5 years ago

Hi...>! i'm getting this error in python3 but not in python2 even i have updated scapy and scapy-http on latest release ?

i'm writing a simple packet sniffer with which i can monitor the traffic so that i can get packets in my desire output format

WARNING: Unless called manually, this could indicate deprecated use. Should be changed to bytes(self)
Source IP               : xxxxxxxxx
Source mac_address      : xxxxxxxxx
Destination IP          : xxxxxxxx
Destination mac_address : xxxxxxxxx
Destination PORT        : 80
Traceback (most recent call last):
  File "/root/Desktop/PythonForH/src/Packet_sniffer/packet_sniffer.py", line 24, in <module>
    sniff("wlan1")
  File "/root/Desktop/PythonForH/src/Packet_sniffer/packet_sniffer.py", line 9, in sniff
    scapy.sniff(iface=interface, store=False, prn=sniff_callback)
  File "/root/Desktop/PythonForH/venv/lib/python3.7/site-packages/scapy/sendrecv.py", line 603, in sniff
    r = prn(p)
  File "/root/Desktop/PythonForH/src/Packet_sniffer/packet_sniffer.py", line 18, in sniff_callback
    print(Fore.BLUE + Style.BRIGHT + "HTTP Packet             : " + Fore.RED + Style.BRIGHT + str(packet[3]))
  File "/root/Desktop/PythonForH/venv/lib/python3.7/site-packages/scapy/packet.py", line 289, in __str__
    return repr(bytes(self)) 
  File "/root/Desktop/PythonForH/venv/lib/python3.7/site-packages/scapy/packet.py", line 291, in __bytes__
    return self.build()
  File "/root/Desktop/PythonForH/venv/lib/python3.7/site-packages/scapy/packet.py", line 359, in build
    p = self.do_build()
  File "/root/Desktop/PythonForH/venv/lib/python3.7/site-packages/scapy/packet.py", line 351, in do_build
    pay = self.do_build_payload()
  File "/root/Desktop/PythonForH/venv/lib/python3.7/site-packages/scapy/packet.py", line 343, in do_build_payload
    return self.payload.do_build()
  File "/root/Desktop/PythonForH/venv/lib/python3.7/site-packages/scapy/packet.py", line 348, in do_build
    pkt = self.self_build()
  File "/root/Desktop/PythonForH/venv/lib/python3.7/site-packages/scapy_http/http.py", line 179, in self_build
    return _self_build(self, field_pos_list)
  File "/root/Desktop/PythonForH/venv/lib/python3.7/site-packages/scapy_http/http.py", line 101, in _self_build
    val = _get_field_value(obj, f.name)
  File "/root/Desktop/PythonForH/venv/lib/python3.7/site-packages/scapy_http/http.py", line 74, in _get_field_value
    headers = _parse_headers(val)
  File "/root/Desktop/PythonForH/venv/lib/python3.7/site-packages/scapy_http/http.py", line 18, in _parse_headers
    headers = s.split("\r\n")
TypeError: a bytes-like object is required, not 'str'