[英]Mitmproxy script returns "OSError: [Errno 63] File name too long" when XML response is read
I have a simple "mitmproxy" script which should modify the response's XML body.我有一个简单的“mitmproxy”脚本,它应该修改响应的 XML 正文。 But it seems that the XML body too large because I got the following error "OSError: [Errno 63] File name too long: '<?xml version="1.0" encodin..."
但似乎 XML 正文太大,因为我收到以下错误“OSError: [Errno 63] File name too long: '<?xml version="1.0" encodin...”
from mitmproxy import ctx
from mitmproxy import http
import xml.etree.ElementTree as ET
def response(flow: http.HTTPFlow) -> None:
if flow.request.pretty_url.endswith("/someurl"):
tree = ET.parse(flow.response.get_text())
root = tree.getroot()
ET.register_namespace('', 'http://schema.blls.com/')
for name in root.iter('name'):
name.text = "joesmith"
# tree = ET.ElementTree(root)
tree.write(flow.response.text, encoding="UTF-8", xml_declaration=True)
And when I run the script I got the error:当我运行脚本时,我得到了错误:
% mitmdump -s test.py
172.20.10.4:57657: GET https://.../someurl
<< 200 OK 1.63k
Addon error: Traceback (most recent call last):
File "test.py", line 7, in response
tree = ET.parse(flow.response.get_text())
File "/usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/xml/etree/ElementTree.py", line 1229, in parse
tree.parse(source, parser)
File "/usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/xml/etree/ElementTree.py", line 569, in parse
source = open(source, "rb")
OSError: [Errno 63] File name too long: '<?xml version="1.0" encoding="UTF-8...
Could you tell me what I'm doing wrong?你能告诉我我做错了什么吗? Thanks!
谢谢!
It looks like ET.parse
expects a filename, not the contents of the file.看起来
ET.parse
需要一个文件名,而不是文件的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.