Closed chencjiajy closed 3 years ago
从日志来看,成功连接到了dubbo 的provider, 但是在解码时报错KeyErroor:90
received response head with invoke_id=0, host=127.0.0.1:21085 received normal response body with invoke_id=0, host=127.0.0.1:21085 90 Traceback (most recent call last): File "/home/dobbo_test/dubbo/connection/connections.py", line 226, in _parse_response result = res.read_next() File "/home/dobbo_test/dubbo/codec/decoder.py", line 414, in read_next return func(self) File "/home/dobbo_test/dubbo/codec/decoder.py", line 311, in read_list result.append(self.read_next()) File "/home/dobbo_test/dubbo/codec/decoder.py", line 414, in read_next return func(self) File "/home/dobbo_test/dubbo/codec/decoder.py", line 242, in read_object field_value = self.read_next() File "/home/dobbo_test/dubbo/codec/decoder.py", line 414, in read_next return func(self) File "/home/dobbo_test/dubbo/codec/decoder.py", line 300, in read_list result.append(self.read_next()) File "/home/dobbo_test/dubbo/codec/decoder.py", line 414, in read_next return func(self) File "/home/dobbo_test/dubbo/codec/decoder.py", line 270, in read_class return self.read_object() File "/home/dobbo_test/dubbo/codec/decoder.py", line 52, in wrapper return func(*args, **kwargs) # 原始方法正常执行 File "/home/dobbo_test/dubbo/codec/decoder.py", line 242, in read_object field_value = self.read_next() File "/home/dobbo_test/dubbo/codec/decoder.py", line 414, in read_next return func(self) File "/home/dobbo_test/dubbo/codec/decoder.py", line 374, in read_map value = self.read_next() File "/home/dobbo_test/dubbo/codec/decoder.py", line 413, in read_next func = functions[data_type] KeyError: 90 Event set, invoked_id=0 90 NoneType: None Exception 90 for host 127.0.0.1:21085
这种解码错误出现在当返回数据中包含了字典类型时,源代码decode.py
的read_map
函数有个小bug,修改代码之后可以避免这个异常
原代码:
@ranges(ord('H'), ord('M'))
def read_map(self):
"""
读取一个dict
:return:
"""
value = self.read_byte()
if value == ord('M') or value == ord('H'):
result = {}
self.objects.append(result)
while self.get_byte() != ord('Z'):
key = self.read_next()
value = self.read_next()
result[key] = value
self.read_byte() # 干掉最后一个'Z'字符
return result
else:
raise HessianTypeError('{0} is not a map.'.format(value))
修改后:
@ranges(ord('H'), ord('M'))
def read_map(self):
"""
读取一个dict
:return:
"""
value = self.read_byte()
if value == ord('M') or value == ord('H'):
result = {}
self.objects.append(result)
while self.get_byte() != ord('Z'):
key = self.read_next()
try:
value = self.read_next()
result[key] = value
except KeyError:
break
self.read_byte() # 干掉最后一个'Z'字符
return result
else:
raise HessianTypeError('{0} is not a map.'.format(value))
从日志来看,成功连接到了dubbo 的provider, 但是在解码时报错KeyErroor:90