mitmdump抓包输出获取flow.response.text的时候报错OSError when decoding,如何解决??

# -*- coding: utf-8 -*-
import json
import os


def response(flow):
    if 'xcx.xxx.com/' in flow.request.url:
        jsondata = json.loads(flow.response.text)
        stoken = jsondata['result']['sessionToken']
        data = {
            'stoken': stoken,
            'uagent': flow.request.headers['User-Agent']
        }
        print(f'获取新的 token : {stoken} ')
        with open('token_8889.txt', 'w', encoding='utf-8') as f:
            f.write(json.dumps(data))

# 命令
# cd 小程序_自动化
# mitmdump -p 8889 -s mitm_8889.py
if __name__ == '__main__':
    cmdstr = "mitmdump -p 8889 -s mitm_8889.py"
    print(cmdstr)
    os.system(cmdstr)

======================================

上面为抓包代码,删减了一些,和下面报错的行数是对不上的

================================

 

                  << 200 OK 5.7k
Addon error: Traceback (most recent call last):
  File "d:\python\lib\site-packages\mitmproxy\net\http\encoding.py", line 67, in decode
    decoded = custom_decode[encoding](encoded)
  File "d:\python\lib\site-packages\mitmproxy\net\http\encoding.py", line 152, in decode_gzip
    return gfile.read()
  File "d:\python\lib\gzip.py", line 276, in read
    return self._buffer.read(size)
  File "d:\python\lib\gzip.py", line 463, in read
    if not self._read_gzip_header():
  File "d:\python\lib\gzip.py", line 411, in _read_gzip_header
    raise OSError('Not a gzipped file (%r)' % magic)
OSError: Not a gzipped file (b'\n')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "mitm_8890.py", line 20, in response
    jsondata = json.loads(flow.response.text)
  File "d:\python\lib\site-packages\mitmproxy\net\http\message.py", line 227, in get_text
    content = self.get_content(strict)
  File "d:\python\lib\site-packages\mitmproxy\net\http\message.py", line 134, in get_content
    content = encoding.decode(self.raw_content, ce)
  File "d:\python\lib\site-packages\mitmproxy\net\http\encoding.py", line 80, in decode
    repr(e),
ValueError: OSError when decoding b'\x1f\x8b with 'gzip': OSError("Not a gzipped file (b'\\n')")

192.168.10.44:60254: GET https:

=============================================================================================================

win7使用mitmdump抓包,输出获取flow.response.text的时候报了上面的错误,是什么原因?路过知道的留言给点意见

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值