fdfs_client-py icon indicating copy to clipboard operation
fdfs_client-py copied to clipboard

python3下的问题

Open xujiang1 opened this issue 6 years ago • 4 comments

我尝试了在python2下可以正常运行 但python3.6下并不能

xujiang1 avatar Mar 14 '18 08:03 xujiang1

关于这个问题 我进行补充 主要报错为struct.error: char format requires a bytes object of length 1

经过跟踪发现问题出在storage_client.py的storage_set_metadata方法的struct.pack 在调用这个方法时出错 我大概查了下 https://www.zhaokeli.com/article/8000.html 这是fmt的对应关系 然后我打印了里面的参数 发现第4个和第7个参数是str 而第 5和6个参数是bytes 这就是问题所在了 追踪第4个参数op_flag 对应到 STORAGE_SET_METADATA_FLAG_OVERWRITE 将他改成 STORAGE_SET_METADATA_FLAG_OVERWRITE= b'0' 不知是o还是 0 另一个参数在函数中修改如下 def fdfs_pack_metadata(meta_dict): ret = b'' for key in meta_dict: ret += b'%s%c%s%c' % (key.encode("utf-8"), FDFS_FIELD_SEPERATOR, meta_dict[key].encode("utf-8"), FDFS_RECORD_SEPERATOR) return ret[0:-1] 该函数在fdfs_protol.py下 请自行查找对比区别 这是我为兼容python3做出的修改 不知会不会对python2下的使用有影响 请作者参考修改以便兼容2和3 还有两个变量需要修改 FDFS_RECORD_SEPERATOR = b'\x01' FDFS_FIELD_SEPERATOR = b'\x02'

xujiang1 avatar Mar 14 '18 10:03 xujiang1

@xujiang1 能提供下python3 的源码吗?

xlyoung avatar Nov 30 '18 04:11 xlyoung

我尝试了在python2下可以正常运行 但python3.6下并不能

你竟然能在python 2下正常 运行?!! 赶紧交流交流

jihch avatar Mar 27 '19 16:03 jihch

python3 不兼容! 各位

DDusky avatar Dec 24 '20 08:12 DDusky