scapy-http
scapy-http copied to clipboard
TypeError: a bytes-like object is required, not 'str'
Hi, While converting a python2 script to python3 I noticed a bug in your library:
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'
I will open a PR which addresses this.
To fix this, you need to make similar changes: diff http.py myhttp.py
18c18,22
< headers = s.split("\r\n")
---
> try:
> headers = s.split("\r\n")
> except TypeError as err:
> headers = s.split(b"\r\n")
>
109c113,117
< 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))