Scapy-htttp TypeError: a bytes-like object is required, not 'str'
使用环境
python3.7
scapy2.4.3
scapy-http1.8.2
问题
引入scapy-http库后,保存报文保错:
Traceback (most recent call last):
....
File "/opt/lib/scapy_http/http.py", line 179, in self_build
return _self_build(self, field_pos_list)
File "/opt/lib/scapy_http/http.py", line 101, in _self_build
val = _get_field_value(obj, f.name)
File "/opt/lib/scapy_http/http.py", line 74, in _get_field_value
headers = _parse_headers(val)
File "/opt/lib/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是基于python2的
解决方法
修改http.py
第18行:
headers = s.split("\r\n")
修改为:
try:
headers = s.split("\r\n")
except TypeError as err:
headers = s.split(b"\r\n")
第113行:
p = f.addfield(obj, p, val + separator)
修改为:
try:
p = f.addfield(obj, p, val + separator)
except TypeError as err:
p = f.addfield(obj, p, str(val) + str(separator))