开发者社区> 问答> 正文

thrift0.13搭建rpc服务,测试时报错tsocket read 0 bytes,寻求帮助。

这几天使用Python3.7 flask thrift0.13搭建rpc服务,服务运行起来后测试访问,报错tsocket read 0 bytes,调试了几个地方也没有解决,希望熟悉这方面的大神,能耐心指点一下,谢谢。QQ截图20200920201019.jpg

展开
收起
游客j6cw3oxlezm2y 2020-09-20 21:08:14 1427 0
1 条回答
写回答
取消 提交回答
  • 下一站是幸福

    从thrift的官方文档中可以知道,如下:

    Base Types
    The base types were selected with the goal of simplicity
    and clarity rather than abundance, focusing on the key types available
    in all programming languages.
    
    bool: A boolean value (true or false)
    byte: An 8-bit signed integer
    i16: A 16-bit signed integer
    i32: A 32-bit signed integer
    i64: A 64-bit signed integer
    double: A 64-bit floating point number
    string: A text string encoded using UTF-8 encoding
    

    注意最后一句加粗的地方 A text string encoded using UTF-8 encoding。使用utf8编码的string类型。 因为官方手册给出的demo都是英文的string类型,所以运行起来是不会报错的。但是在我们的实际项目中,往往是有中文的。 因此,我这里做了一个统一处理:

    def serialize_to(obj, tobj): tobj = tobj() for k, v in tobj.dict.iteritems(): value = getattr(obj, k) if isinstance(value, datetime): value = int(datetime2utc(value)) if isinstance(value, unicode): # 注意这里 # value = value.encode('utf8') pass setattr(tobj, k, value) return tobj

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    

    注意注释掉的部分,按照上面官方文档中说的,通过utf8对字符encode。结果server启动之后client访问就会报错TSocket read 0 bytes。

    最终一步一步排查,终于发现此问题。 版本升级要谨慎。!!

    2021-04-02 22:07:00
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
移动互联网测试到质量的转变 立即下载
给ITer的技术实战进阶课-阿里CIO学院独家教材(四) 立即下载
F2etest — 多浏览器兼容性测试整体解决方案 立即下载