我正在使用paramiko库ssh到路由器并运行sh操作命令,其中输出非常大(> 500MB),并且它会引发内存错误。有没有办法重新编写我的代码,因此它不会将所有数据都放入内存并引发错误。
stdin, stdout, stderr = ssh_session.execute_command(' '.join(['show operational',request,'xml'])) #request is just a str represnting the differnet components (AAA, etc.)
process_output(''.join(stdout.readlines()),request) #stdout.readlines() is what causes the memory error
ssh_session.close()
错误:
polling IPV6_RIB
Exception: Expecting packet from (31,), got 94
Traceback (most recent call last):
File "/home/lab/5.3.2_xml/py3/lib/python3.4/site-packages/paramiko/transport.py", line 1607, in run
raise SSHException('Expecting packet from %r, got %d' % (self._expected_packet, ptype))
paramiko.ssh_exception.SSHException: Expecting packet from (31,), got 94
Traceback (most recent call last):
File "xml_oper.py", line 42, in <module>
main()
File "xml_oper.py", line 37, in main
process_output(''.join(stdout.readlines()),request)
MemoryError