Estoy intentando que el código de Python 2 se ejecute en Python 3, y esta línea
argv = (c_char_p * len(args))(*args)
causa este error
File "/Users/hanxue/Code/Python/gsfs/src/gsfs.py", line 381, in main fuse = FUSE(GoogleStorageFUSE(username, password, logfile=logfile), mount_point, **fuse_args) File "/Users/hanxue/Code/Python/gsfs/src/fuse.py", line 205, in __init__ argv = (c_char_p * len(args))(*args) TypeError: bytes or integer address expected instead of str instance
Este es el método completo.
class FUSE(object): """This class is the lower level interface and should not be subclassed under normal use. Its methods are called by fuse""" def __init__(self, operations, mountpoint, raw_fi=False, **kwargs): """Setting raw_fi to True will cause FUSE to pass the fuse_file_info class as is to Operations, instead of just the fh field. This gives you access to direct_io, keep_cache, etc.""" self.operations = operations self.raw_fi = raw_fi args = ['fuse'] if kwargs.pop('foreground', False): args.append('-f') if kwargs.pop('debug', False): args.append('-d') if kwargs.pop('nothreads', False): args.append('-s') kwargs.setdefault('fsname', operations.__class__.__name__) args.append('-o') args.append(','.join(key if val == True else '%s=%s' % (key, val) for key, val in kwargs.items())) args.append(mountpoint) argv = (c_char_p * len(args))(*args)
Que es invocado por esta línea.
fuse = FUSE(GoogleStorageFUSE(username, password, logfile=logfile), mount_point, **fuse_args)
¿Cómo evito el error cambiando los argumentos en byte[]
?
En Python 3, todos los literales de cadena son, por defecto, unicode. Así que las frases 'fuse'
, '-f'
, '-d'
, etc, crean instancias de str
. Para obtener instancias de bytes
, tendrá que hacer ambas cosas:
username
, password
, logfile
, punto de mount_point
y cada fuse_args
en fuse_args
b'fuse'
, b'-f'
, b'-d'
, etc. Este no es un trabajo pequeño.