gpt4 book ai didi

Python 3 类型错误 : bytes or integer address expected instead of str instance

转载 作者:太空宇宙 更新时间:2023-11-03 18:27:54 26 4
gpt4 key购买 nike

我正在尝试让 Python 2 代码在 Python 3 上运行,而这一行

    argv = (c_char_p * len(args))(*args)

导致此错误

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

这是完整的方法

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)

由该行调用

fuse = FUSE(GoogleStorageFUSE(username, password, logfile=logfile), mount_point, **fuse_args)

如何通过将参数更改为 byte[] 来避免错误?

最佳答案

在 Python 3 中,默认情况下所有字符串文字都是 unicode。所以短语 'fuse' , '-f' , '-d'等,全部创建str实例。为了得到bytes相反,您将需要同时执行以下两项操作:

  • 将字节传递到 FUSE( usernamepasswordlogfilemount_point 以及 fuse_args 中的每个参数
  • 将 FUSE 本身中的所有字符串文字更改为字节:b'fuse' , b'-f' , b'-d'等等

这不是一项小工作。

关于Python 3 类型错误 : bytes or integer address expected instead of str instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22873437/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com