{"action":"closed","issue":{"url":"https://api.github.com/repos/mitmproxy/mitmproxy/issues/662","labels_url":"https://api.github.com/repos/mitmproxy/mitmproxy/issues/662/labels{/name}","comments_url":"https://api.github.com/repos/mitmproxy/mitmproxy/issues/662/comments","events_url":"https://api.github.com/repos/mitmproxy/mitmproxy/issues/662/events","html_url":"https://github.com/mitmproxy/mitmproxy/issues/662","id":92113052,"number":662,"title":"New error in custom inline-script and provided example","user":{"login":"mame82","id":13119970,"avatar_url":"https://avatars.githubusercontent.com/u/13119970?v=3","gravatar_id":"","url":"https://api.github.com/users/mame82","html_url":"https://github.com/mame82","followers_url":"https://api.github.com/users/mame82/followers","following_url":"https://api.github.com/users/mame82/following{/other_user}","gists_url":"https://api.github.com/users/mame82/gists{/gist_id}","starred_url":"https://api.github.com/users/mame82/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mame82/subscriptions","organizations_url":"https://api.github.com/users/mame82/orgs","repos_url":"https://api.github.com/users/mame82/repos","events_url":"https://api.github.com/users/mame82/events{/privacy}","received_events_url":"https://api.github.com/users/mame82/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-30T14:43:31Z","updated_at":"2015-07-21T09:58:27Z","closed_at":"2015-07-21T09:58:27Z","body":"Hey, \r\n\r\nI've got a proble with a custom inline-script, running mitmproxy-0.12.1 (not the provided 11.3) on kali-1.1.0, after an `apt-get upgrade`. So I don't know exactly what causes the problem, but it wasn't there before.\r\n\r\nThe custom script-code (stripped down to error parts)\r\n```\r\nfrom libmproxy.protocol.http import decoded\r\nfrom bs4 import BeautifulSoup\r\n\r\ndef response(context, flow):\r\n\tif flow.response.headers.get_first(\"content-type\", \"\").startswith(\"text/html\"):\r\n\t\twith decoded(flow.response):  # automatically decode gzipped responses.\r\n\t\t\t# context.log(\"Type \" + str(type(flow.response.content)))\r\n\t\t\thtml = BeautifulSoup(flow.response.content)\r\n\t\t\tif html.head:\r\n\t\t\t\t# here some header-modifying-code, which isn't relevant for raising this error\r\n\t\t\t\tflow.response.content = str(html)\r\n\t\t\t\tcontext.log(\"Manipulated response header.\")\r\n```\r\n\r\nError-Dump of mitmproxy/mitmdump\r\n```\r\nScript error:\r\nTraceback (most recent call last):\r\n  File \"/usr/local/lib/python2.7/dist-packages/mitmproxy-0.12.1-py2.7.egg/libmproxy/script.py\", line 123, in run\r\n    return (True, f(self.ctx, *args, **kwargs))\r\n  File \"/usr/share/doc/mitmproxy/examples/modify_response_header_error.py\", line 12, in response\r\n    context.log(\"Manipulated response header.\")\r\n  File \"/usr/local/lib/python2.7/dist-packages/mitmproxy-0.12.1-py2.7.egg/libmproxy/protocol/http.py\", line 78, in __exit__\r\n    self.o.encode(self.ce)\r\n  File \"/usr/local/lib/python2.7/dist-packages/mitmproxy-0.12.1-py2.7.egg/libmproxy/protocol/http.py\", line 151, in encode\r\n    self.content = encoding.encode(e, self.content)\r\n  File \"/usr/local/lib/python2.7/dist-packages/mitmproxy-0.12.1-py2.7.egg/libmproxy/encoding.py\", line 33, in encode\r\n    return encoding_map[e](content)\r\n  File \"/usr/local/lib/python2.7/dist-packages/mitmproxy-0.12.1-py2.7.egg/libmproxy/encoding.py\", line 55, in encode_gzip\r\n    gf.write(content)\r\n  File \"/usr/lib/python2.7/gzip.py\", line 228, in write\r\n    if len(data) > 0:\r\nTypeError: object of type 'int' has no len()\r\n```\r\n\r\nencoding.py shouldn't have changed since my last usage of the script (and it worked)\r\nFor testing I've changed the `if html.head:` to `if html.head and html.body:` to make sure there's content present before encoding again, but with no effect.\r\nComparing to the examples, I've found that `iframe_injector.py` is producing exactly the same error because it uses the decoded() method.\r\n\r\n```\r\nScript error:\r\nTraceback (most recent call last):\r\n  File \"/usr/local/lib/python2.7/dist-packages/mitmproxy-0.12.1-py2.7.egg/libmproxy/script.py\", line 123, in run\r\n    return (True, f(self.ctx, *args, **kwargs))\r\n  File \"/usr/share/doc/mitmproxy/examples/iframe_injector.py\", line 27, in response\r\n    context.log(\"Iframe inserted.\")\r\n  File \"/usr/local/lib/python2.7/dist-packages/mitmproxy-0.12.1-py2.7.egg/libmproxy/protocol/http.py\", line 78, in __exit__\r\n    self.o.encode(self.ce)\r\n  File \"/usr/local/lib/python2.7/dist-packages/mitmproxy-0.12.1-py2.7.egg/libmproxy/protocol/http.py\", line 151, in encode\r\n    self.content = encoding.encode(e, self.content)\r\n  File \"/usr/local/lib/python2.7/dist-packages/mitmproxy-0.12.1-py2.7.egg/libmproxy/encoding.py\", line 33, in encode\r\n    return encoding_map[e](content)\r\n  File \"/usr/local/lib/python2.7/dist-packages/mitmproxy-0.12.1-py2.7.egg/libmproxy/encoding.py\", line 55, in encode_gzip\r\n    gf.write(content)\r\n  File \"/usr/lib/python2.7/gzip.py\", line 228, in write\r\n    if len(data) > 0:\r\nTypeError: object of type 'int' has no len()\r\n\r\n```"}}