Issue
I'm having an old Python script in version 2.7, which uses the function Paramiko Channel.recv()
method. I'm trying to migrate the script into a Python version 3 (and Paramiko 2.7.1), but the documentation says:
:return: received data, as a
str
/bytes
.
Since the major problems when migrating from Python 2 to Python 3 are the different basestrings, I need a more concrete specification of the return type.
What does the function's return type depend on? Or: How can I be sure, that the return value is always the same (e.g. bytestring)?
Some code-snippet:
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()
Solution
In Python 3, the method always returns bytes
.
In Python 2, the method returns a string.
Answered By - Martin Prikryl
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.