Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: a bytes-like object is required, not 'str' #26

Open
sim0nx opened this issue Jul 12, 2017 · 1 comment · May be fixed by #27
Open

TypeError: a bytes-like object is required, not 'str' #26

sim0nx opened this issue Jul 12, 2017 · 1 comment · May be fixed by #27

Comments

@sim0nx
Copy link

sim0nx commented Jul 12, 2017

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.

@jaroslaw-wieczorek
Copy link

jaroslaw-wieczorek commented Dec 4, 2018

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))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants