You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BufferedFile TypeError on write with buffer API objects #967
Unlike normal files, the paramiko BufferedFile.write() method throws a TypeError if passed an object that implements the buffer API, such as the builtin memoryview type.
Note this a Python 3 flavoured version of #285 from porting that code away from the old buffer type.
Traceback (most recent call last):
...
File ".../osutils.py", line 753, in pump_string_file
write(view[offset:offset+segment_size])
File ".../paramiko/file.py", line 375, in write
data = b(data)
File ".../paramiko/py3compat.py", line 47, in b
raise TypeError("Expected unicode or bytes, got %r" % s)
TypeError: Expected unicode or bytes, got <memory at 0x7f0ce4d08510>
Paramiko should not care about the types it is passed, provided they are len-able and can be written to the underlying (BytesIO here) object.
Missed the full path through SFTPFIle with the first pass fix, there's a secondary failure:
Traceback (most recent call last):
...
File ".../breezy/osutils.py", line 753, in pump_string_file
write(view[offset:offset+segment_size])
File ".../paramiko/file.py", line 339, in write
self._write_all(data)
File ".../paramiko/file.py", line 456, in _write_all
count = self._write(data)
File ".../paramiko/sftp_file.py", line 176, in _write
self._reqs.append(self.sftp._async_request(type(None), CMD_WRITE, self.handle, long(self._realpos), data[:chunk]))
File ".../paramiko/sftp_client.py", line 748, in _async_request
raise Exception('unknown type for %r type %r' % (item, type(item)))
Exception: unknown type for <memory at 0xb5613b70> type <type 'memoryview'>
Looks like _async_request should just try treat args as string by default.
Activity
Allow any buffer type to written to BufferedFile
Allow any buffer type to written to BufferedFile
bz2 commentedon May 25, 2017
Missed the full path through
SFTPFIlewith the first pass fix, there's a secondary failure:Looks like _async_request should just try treat args as string by default.
Allow any buffer type to be written to SFTPFile
bitprophet commentedon May 31, 2017
Rolling into the final PR. Thanks!
Allow any buffer type to written to BufferedFile
Allow any buffer type to be written to SFTPFile
Allow any buffer type to written to BufferedFile
Allow any buffer type to be written to SFTPFile