Skip to content

Allow converting newbytes to python2 str #142

Open
@adiroiban

Description

@adiroiban

I have a problem with using grp.getgrnam on Py2.7
I found out that it needs str and does not work with bytes.

Not sure where I should report this but maybe the report could help others who bump on this issue.

(Pdb) name
'str2844-cp\u021b'
(Pdb) type(name)
<class 'future.types.newstr.newstr'>

name_encoded = name.encode('utf-8')
(Pdb) type(name_encoded)
<class 'future.types.newbytes.newbytes'>
(Pdb) name_encoded
b'str2844-cp\xc8\x9b'

(Pdb) grp.getgrnam(name_encoded)
*** KeyError: "getgrnam(): name not found: b'str2844-cp\xc8\x9b'"
(Pdb) grp.getgrnam('str2844-cp\xc8\x9b')
grp.struct_group(gr_name='str2844-cp\xc8\x9b', gr_passwd='x', gr_gid=2948, gr_mem=[])

As I workaround I went for

import codecs
name_encoded = codecs.encode(name, 'utf-8')

Thanks!

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