aboutsummaryrefslogtreecommitdiffstats
path: root/examples/har_dump.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/har_dump.py')
-rw-r--r--examples/har_dump.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/examples/har_dump.py b/examples/har_dump.py
index 560b9adc..3ba08968 100644
--- a/examples/har_dump.py
+++ b/examples/har_dump.py
@@ -139,7 +139,7 @@ def response(flow):
if flow.request.method in ["POST", "PUT", "PATCH"]:
entry["request"]["postData"] = {
"mimeType": flow.request.headers.get("Content-Type", "").split(";")[0],
- "text": flow.request.content,
+ "text": _always_string(flow.request.content),
"params": name_value(flow.request.urlencoded_form)
}
@@ -213,4 +213,12 @@ def name_value(obj):
"""
Convert (key, value) pairs to HAR format.
"""
- return [{"name": k, "value": v} for k, v in obj.items()]
+ return [{"name": _always_string(k), "value": _always_string(v)} for k, v in obj.items()]
+
+def _always_string(byte_or_str):
+ """
+ Makes sure we get text back instead of `bytes` since json.dumps dies on `bytes`
+ """
+ if isinstance(byte_or_str, bytes):
+ return byte_or_str.decode('utf8')
+ return byte_or_str