spin6lock / python-sproto

python binding to sproto

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

使用binary类型的字段会报错

ffbh123456 opened this issue · comments

commented

看报错好像是sproto.decode的时候把binary当做utf-8的string了?

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x81 in position 0: invalid start byte
The above exception was the direct cause of the following exception:

commented

分支是py3_test

看着像是

data = Py_BuildValue("s#", (char*)args->value, length);
这一行,我看文档:https://docs.python.org/3/c-api/arg.html#c.Py_BuildValue 的确是用utf8来构建string的,是不是这里我返回一个bytes数组比较合理?

commented

是的,我把s#改成了y#好像就可以了

commented

sproto_encode可能也有问题,不过我没有测试过

@ZhouJiaZhi 非常感谢!修复了一版,可以更新py3_test分支后再试

commented

测了下没有发现问题,感谢