From 8e8017e382eb814bf1f44ecb9e35544ef32cde79 Mon Sep 17 00:00:00 2001 From: Guy Sheffer Date: Tue, 20 Mar 2018 12:02:13 +0200 Subject: [PATCH] Handle non-unicode chars in url --- proxy2.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/proxy2.py b/proxy2.py index f502e8c..0dc2892 100644 --- a/proxy2.py +++ b/proxy2.py @@ -288,7 +288,10 @@ def send_cacert(self): def print_info(self, req, req_body, res, res_body): def parse_qsl(s): - return '\n'.join("{:<20} {}".format(k, v) for k, v in urlparse.parse_qsl(s, keep_blank_values=True)) + if type(s) == bytes: + return '\n'.join("{:<20} {}".format(k, v) for k, v in urlparse.parse_qsl(s, keep_blank_values=True)) + else: + return '\n'.join("{:<20} {}".format(k, v) for k, v in urlparse.parse_qsl(s.decode("utf-8"), keep_blank_values=True)) req_header_text = "{} {} {}\n{}".format(req.command, req.path, req.request_version, req.headers) res_header_text = "{} {} {}\n{}".format(res.response_version, res.status, res.reason, res.headers)