【发布时间】:2021-02-03 13:19:02
【问题描述】:
我有一个 2.7 版的旧 Python 脚本,它使用函数 Paramiko Channel.recv() 方法。我正在尝试将脚本迁移到 Python 版本 3(和 Paramiko 2.7.1),但文档说:
:return: 接收到的数据,作为
str/bytes。
由于从 Python 2 迁移到 Python 3 时的主要问题是不同的基本字符串,因此我需要更具体的返回类型规范。
函数的返回类型取决于什么?或者:我如何确定返回值总是相同的(例如字节串)?
一些代码-sn-p:
t = paramiko.Transport(socklike_obj)
t.start_client()
t.auth_password(usr, pw)
chan = t.open_session()
nbytes = 2**16-1 # 65535
out = chan.recv(nbytes)
while out != b'': # or: out != ''
if b'\n' in out or b'\r' in out:
parts = out.splitlines()
【问题讨论】:
标签: python python-3.x ssh python-2.x paramiko