需要一个类似字节的对象,而不是 'str' :TypeError
a bytes-like object is required, not 'str' : TypeError
我正在使用 python-3.7 构建一个嗅探工具,当我尝试使用 scapy_http
模块时遇到了这个错误。
它在 python-2.x 中工作正常。
对象类型为 scapy.layers.l2.Ether
def process(packet):
if packet.haslayer(http.HTTPResponse):
print(packet)
> Traceback (most recent call last): File "sniffer.py", line 13, in
> <module>
> sniff("wlan0") File "sniffer.py", line 6, in sniff
> scapy.sniff(iface=interface, store=False,prn=process) File "/usr/local/lib/python3.7/dist-packages/scapy/sendrecv.py", line 886,
> in sniff
> r = prn(p) File "sniffer.py", line 10, in process
> print(packet) File "/usr/local/lib/python3.7/dist-packages/scapy/packet.py", line 438, in
> __str__
> return str(self.build()) File "/usr/local/lib/python3.7/dist-packages/scapy/packet.py", line 556, in
> build
> p = self.do_build() File "/usr/local/lib/python3.7/dist-packages/scapy/packet.py", line 541, in
> do_build
> pay = self.do_build_payload() File "/usr/local/lib/python3.7/dist-packages/scapy/packet.py", line 528, in
> do_build_payload
> return self.payload.do_build() File "/usr/local/lib/python3.7/dist-packages/scapy/packet.py", line 541, in
> do_build
> pay = self.do_build_payload() File "/usr/local/lib/python3.7/dist-packages/scapy/packet.py", line 528, in
> do_build_payload
> return self.payload.do_build() File "/usr/local/lib/python3.7/dist-packages/scapy/packet.py", line 541, in
> do_build
> pay = self.do_build_payload() File "/usr/local/lib/python3.7/dist-packages/scapy/packet.py", line 528, in
> do_build_payload
> return self.payload.do_build() File "/usr/local/lib/python3.7/dist-packages/scapy/packet.py", line 541, in
> do_build
> pay = self.do_build_payload() File "/usr/local/lib/python3.7/dist-packages/scapy/packet.py", line 528, in
> do_build_payload
> return self.payload.do_build() File "/usr/local/lib/python3.7/dist-packages/scapy/packet.py", line 538, in
> do_build
> pkt = self.self_build() File "/usr/local/lib/python3.7/dist-packages/scapy_http/http.py", line 227,
> in self_build
> return _self_build(self, field_pos_list) File "/usr/local/lib/python3.7/dist-packages/scapy_http/http.py", line 101,
> in _self_build
> val = _get_field_value(obj, f.name) File "/usr/local/lib/python3.7/dist-packages/scapy_http/http.py", line 74,
> in _get_field_value
> headers = _parse_headers(val) File "/usr/local/lib/python3.7/dist-packages/scapy_http/http.py", line 18,
> in _parse_headers
> headers = s.split("\r\n") TypeError: a bytes-like object is required, not 'str'
scapy_http
已弃用(不适用于 Python 3),HTTP 模块现在默认包含在 Scapy 中。
请升级到GitHub版本或最新的RC:
pip install scapy --upgrade --pre
我正在使用 python-3.7 构建一个嗅探工具,当我尝试使用 scapy_http
模块时遇到了这个错误。
它在 python-2.x 中工作正常。
对象类型为 scapy.layers.l2.Ether
def process(packet):
if packet.haslayer(http.HTTPResponse):
print(packet)
> Traceback (most recent call last): File "sniffer.py", line 13, in
> <module>
> sniff("wlan0") File "sniffer.py", line 6, in sniff
> scapy.sniff(iface=interface, store=False,prn=process) File "/usr/local/lib/python3.7/dist-packages/scapy/sendrecv.py", line 886,
> in sniff
> r = prn(p) File "sniffer.py", line 10, in process
> print(packet) File "/usr/local/lib/python3.7/dist-packages/scapy/packet.py", line 438, in
> __str__
> return str(self.build()) File "/usr/local/lib/python3.7/dist-packages/scapy/packet.py", line 556, in
> build
> p = self.do_build() File "/usr/local/lib/python3.7/dist-packages/scapy/packet.py", line 541, in
> do_build
> pay = self.do_build_payload() File "/usr/local/lib/python3.7/dist-packages/scapy/packet.py", line 528, in
> do_build_payload
> return self.payload.do_build() File "/usr/local/lib/python3.7/dist-packages/scapy/packet.py", line 541, in
> do_build
> pay = self.do_build_payload() File "/usr/local/lib/python3.7/dist-packages/scapy/packet.py", line 528, in
> do_build_payload
> return self.payload.do_build() File "/usr/local/lib/python3.7/dist-packages/scapy/packet.py", line 541, in
> do_build
> pay = self.do_build_payload() File "/usr/local/lib/python3.7/dist-packages/scapy/packet.py", line 528, in
> do_build_payload
> return self.payload.do_build() File "/usr/local/lib/python3.7/dist-packages/scapy/packet.py", line 541, in
> do_build
> pay = self.do_build_payload() File "/usr/local/lib/python3.7/dist-packages/scapy/packet.py", line 528, in
> do_build_payload
> return self.payload.do_build() File "/usr/local/lib/python3.7/dist-packages/scapy/packet.py", line 538, in
> do_build
> pkt = self.self_build() File "/usr/local/lib/python3.7/dist-packages/scapy_http/http.py", line 227,
> in self_build
> return _self_build(self, field_pos_list) File "/usr/local/lib/python3.7/dist-packages/scapy_http/http.py", line 101,
> in _self_build
> val = _get_field_value(obj, f.name) File "/usr/local/lib/python3.7/dist-packages/scapy_http/http.py", line 74,
> in _get_field_value
> headers = _parse_headers(val) File "/usr/local/lib/python3.7/dist-packages/scapy_http/http.py", line 18,
> in _parse_headers
> headers = s.split("\r\n") TypeError: a bytes-like object is required, not 'str'
scapy_http
已弃用(不适用于 Python 3),HTTP 模块现在默认包含在 Scapy 中。
请升级到GitHub版本或最新的RC:
pip install scapy --upgrade --pre