thrift TSocket read 0 bytes(string类型中的一个坑)
来源:互联网 发布:软件开发解决方案总结 编辑:程序博客网 时间:2024/05/16 11:30
最近把thrif从0.9版本升级到0.10版本之后,一些一直在报thrift TSocket read 0 bytes 错误。
此篇文章记录thrift中的一个坑。
从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
注意注释掉的部分,按照上面官方文档中说的,通过utf8对字符encode。结果server启动之后client访问就会报错TSocket read 0 bytes。
最终一步一步排查,终于发现此问题。
版本升级要谨慎。!!
- thrift TSocket read 0 bytes(string类型中的一个坑)
- python使用thrift出现TTransportException: TSocket read 0 bytes
- python借助pysh2连接hiveserver2操作hive数据库时thrift.transport.TTransport.TTransportException: TSocket read 0
- read GBK code from bytes,string operations
- read(bytes)
- thrift-0.8.0 tutorial中的一个错误
- Can not read response from server. Expected to read 4 bytes, read 0 bytes
- Program received signal SIGABRT, Aborted + Thrift transport::TSocket::local_open
- java.io.IOException: Unable to read entire header; 0 bytes read; expected 32 bytes
- Python3中的bytes和str类型
- 浅析Python3中的bytes和str类型
- 浅析Python3中的bytes和str类型
- Error: Read from storage 0 bytes, but requested 12 bytes 的解决方法
- HDFS bytes read与Map input bytes
- thrift之TTransport层的堵塞的套接字I/O传输类TSocket
- thrift之TTransport层的堵塞的套接字I/O传输类TSocket
- Unable to read entire header; bytes read; expected bytes
- Read and write bytes data
- 面向对象的OOA、OOD、OOP
- cat命令
- LintCode 用递归打印数字
- Altium Designer使用技巧总结
- Glide使用心得——加载图片出现浅绿色背景问题和Glide加载完成的监听设置
- thrift TSocket read 0 bytes(string类型中的一个坑)
- rsa加密
- FFmpeg内存操作(三)内存转码器
- php 重写
- CodeForces-771D-Bear and Company
- ruby 如何确定数据类型
- string.h C语言 函数集合
- HTTP 协议中的 Transfer-Encoding
- 查看Linux系统版本的方法