问题转换较旧的 MITMProxy 脚本以在 5.2 上工作 - 替换时出错并且无法找到有关替换内容的文档
Issue Converting Older MITMProxy Scripts to work on 5.2 - Error on Replace and Can't Find Docs on What Replaced was Replaced with
我更新到 MITMProxy 版本 5.2。
更新后,我尝试 运行 一个较旧的脚本并不断收到错误消息:
AttributeError: 'HTTPResponse' object has no attribute 'replace'
来自我的代码:
flow.response.replace('FindThis', 'ReplaceWithThis')
我读到他们更改替换,但找不到任何明确说明他们更改的内容或脚本中正确语法的文档。
我读到 ModifyBody
是替代品,但是当我将脚本从 replace
更改为 ModifyBody
时,我会收到错误消息:
AttributeError: 'HTTPResponse' object has no attribute 'ModifyBody'
所以我假设它不正确或者我需要加载一个模块?我想知道是否有新的或相同的语法。
谢谢
我们删除了 HTTPResponse.replace
,因为不清楚哪些部分(headers,内容)是如何替换的。实际上:
- 使用
flow.response.content = flow.response.content.replace(b"foo", b"bar")
在响应中进行二进制替换 body。
- 使用
flow.response.text = flow.response.text.replace("foo", "bar")
在响应中进行文本替换 body。
- 使用
flow.headers
作为字典进行 header 替换,例如flow.headers["foo"] = "42"
.
我更新到 MITMProxy 版本 5.2。 更新后,我尝试 运行 一个较旧的脚本并不断收到错误消息:
AttributeError: 'HTTPResponse' object has no attribute 'replace'
来自我的代码:
flow.response.replace('FindThis', 'ReplaceWithThis')
我读到他们更改替换,但找不到任何明确说明他们更改的内容或脚本中正确语法的文档。
我读到 ModifyBody
是替代品,但是当我将脚本从 replace
更改为 ModifyBody
时,我会收到错误消息:
AttributeError: 'HTTPResponse' object has no attribute 'ModifyBody'
所以我假设它不正确或者我需要加载一个模块?我想知道是否有新的或相同的语法。
谢谢
我们删除了 HTTPResponse.replace
,因为不清楚哪些部分(headers,内容)是如何替换的。实际上:
- 使用
flow.response.content = flow.response.content.replace(b"foo", b"bar")
在响应中进行二进制替换 body。 - 使用
flow.response.text = flow.response.text.replace("foo", "bar")
在响应中进行文本替换 body。 - 使用
flow.headers
作为字典进行 header 替换,例如flow.headers["foo"] = "42"
.