python struct.pack方法报错argument for 's' must be a bytes object 解决
2020-12-13 03:46
标签:pre stat net href pytho tps bytes size https 参考 https://blog.csdn.net/weixin_38383877/article/details/81100192 在python3下使用struct模块代码 抛出异常: 解决办法: python struct.pack方法报错argument for 's' must be a bytes object 解决 标签:pre stat net href pytho tps bytes size https 原文地址:https://www.cnblogs.com/lqerio/p/11087434.htmlfileHead = struct.pack(‘128sl‘, os.path.basename(filePath),os.stat(filePath).st_size);
argument for ‘s‘ must be a bytes object必须要是字节类型。
把字符串的地方转为字节类型,还要要先转成utf-8的编码(否则报错string argument without an encoding
),代码如下:fileHead = struct.pack(‘128sl‘, bytes(os.path.basename(filePath).encode(‘utf-8‘)),os.stat(filePath).st_size);
文章标题:python struct.pack方法报错argument for 's' must be a bytes object 解决
文章链接:http://soscw.com/essay/28264.html