Skip to content

BytesWarning: str() on a bytes instance #1074

Closed

Description

@Rezney

While running pytest I am getting the following two warnings:

  /usr/lib/python3.6/site-packages/paramiko/sftp_client.py:344: BytesWarning: str() on a bytes instance
    'open(%r, %r) -> %s' % (filename, mode, hexlify(handle)))
  /usr/lib/python3.6/site-packages/paramiko/sftp_file.py:86: BytesWarning: str() on a bytes instance
    self.sftp._log(DEBUG, 'close(%s)' % hexlify(self.handle))

-- Docs: http://doc.pytest.org/en/latest/warnings.html

which I believe is a bug in the code as:

# python3
Python 3.6.2 (default, Sep 22 2017, 08:28:09) 
[GCC 7.2.1 20170915 (Red Hat 7.2.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> from binascii import hexlify
>>> 
>>> hexlify(b'test')
b'74657374'
>>> 
>>> hexlify('test')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: a bytes-like object is required, not 'str'
>>> 

Thanks a lot for taking a look!

Activity

  1. bitprophet commented on Sep 25, 2017

    @bitprophet
    Member

    Don't recall offhand what the handle objects are implemented as but this may just be a minor oversight from the Python 3 overhaul & hopefully fixable by using paramiko.py3compat.b() or similar. Thanks for the report!

  2. Rezney commented on Sep 26, 2017

    @Rezney
    ContributorAuthor

    Thanks for taking a look! PR #1075 submitted.

  3. bitprophet commented on Sep 26, 2017

    @bitprophet
    Member

    Rolling into the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions