script.py:
def response(flow):
if "customstring" in flow.response.content:
>my code>
TypeError: a bytes-like object is required, not 'str'
I need to use b"customstring" instead "customstring". This script was working fine on mitmproxy 0.18 but fails on mitmproxy 2.0.0
Want to use the same script because is very long and was stable on older mitm version. Any way to use strings instead bytes?
Mitmproxy version: 3.0.0 (2.0.0dev0916-0x930d78b5)
Python version: 3.5.3
Platform: Linux-4.9.0-3-amd64-x86_64-with-debian-9.1
Linux distro: debian 9.1
Thanks!
I can't link to this from mobile, but take a look at get_text and get_content at http://docs.mitmproxy.org/en/stable/scripting/api.html#mitmproxy.http.HTTPResponse! .content is bytes, .text is the completely decoded version! Downside of using bytes is that malformed documents may raise an error unless you pass strict=False.
Thanks @mhils !
I'm trying with flow.response.text (instead .content) but no luck, :(
Done!
I was missing the following line:
from mitmproxy import http
and use
def response(flow: http.HTTPFlow) -> None:
instead
def response(flow)
Now .text is working! Thanks @mhils
For the record, the import for the type annotation shouldn't make a difference, but glad you made it work! 馃槂
Most helpful comment
I can't link to this from mobile, but take a look at get_text and get_content at http://docs.mitmproxy.org/en/stable/scripting/api.html#mitmproxy.http.HTTPResponse!
.contentis bytes, .text is the completely decoded version! Downside of using bytes is that malformed documents may raise an error unless you pass strict=False.