GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — `to_bytes()` fails with `TypeError: Expected bytes, got <subclass>` for subclasses of `str`/`bytes` · Issue #106 · ParallelSSH/ssh-python Open DescriptionDescriptionEvery API that goes through
# ssh/utils.pyx cdef bytes to_bytes(_str): if isinstance(_str, bytes): return _str # bytes subclass returned as-is elif isinstance(_str, unicode): return _str.encode(ENCODING) # may return a bytes subclass return _str So both branches can return a Real-world impactThis breaks Ansible NETCONF connections that use libssh ( The same setup works with the paramiko transport. Minimal reproducer (no Ansible required)from ssh.session import Session from ssh.options import HOST class MyBytes(bytes): pass class MyStr(str): def encode(self, *args, **kwargs): return MyBytes(super().encode(*args, **kwargs)) s = Session() s.options_set(HOST, "localhost") # OK s.options_set(HOST, b"localhost") # OK s.options_set(HOST, MyBytes(b"localhost")) # TypeError: Expected bytes, got MyBytes s.options_set(HOST, MyStr("localhost")) # TypeError: Expected bytes, got MyBytes s.userauth_password(MyStr("user"), MyStr("pw")) # TypeError: Expected bytes, got MyBytes Expected behaviourSubclasses of Suggested fixCoerce to an exact cdef bytes to_bytes(_str):
if isinstance(_str, bytes):
return bytes(_str)
elif isinstance(_str, unicode):
return bytes(_str.encode(ENCODING))
return _strEnvironment
Activity
MetadataMetadataAssigneesLabelsNo labels TypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |