# -*- 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的时候报了上面的错误,是什么原因?路过知道的留言给点意见