Python 3 TypeError预期为字节或整数地址,而不是str
it1352
帮助1人
问题说明
我正在尝试让Python 2代码在Python 3上运行,并且此行
I am trying to get Python 2 code to run on Python 3, and this line
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)
怎么办我通过将args更改为 byte []
?
How do I avoid the error by changing the args into byte[]
?
正确答案
#1
在Python 3中,默认情况下,所有字符串文字都是unicode。因此,短语'fuse'
,'-f'
,'-d'
等都创建 str
实例。为了获得个字节
实例,您将需要同时执行以下操作:
In Python 3 all string literals are, by default, unicode. So the phrases 'fuse'
, '-f'
, '-d'
, etc, all create str
instances. In order to get bytes
instances instead you will need to do both:
- pass字节进入FUSE(
用户名
,密码
,日志文件
,mount_point
,并且fuse_args
中的每个arg
- 更改其中的所有字符串文字FUSE本身为字节:
b'fuse'
,b'-f'
,b '-d'
等。
- pass bytes into the FUSE (
username
,password
,logfile
,mount_point
, and each arg infuse_args
- change all the string literals in FUSE itself to be bytes:
b'fuse'
,b'-f'
,b'-d'
, etc.
这不是一件小事。
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcfiebh
系列文章
更多
同类精品
更多
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20