chencjiajy commented on issue #14:
URL: https://github.com/apache/dubbo-python2/issues/14#issuecomment-951598856


   > 从日志来看,成功连接到了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,修改代码之后可以避免这个异常
   原代码:
   ```python
    @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))
   ```
   
   
   修改后:
   ```python
   @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))
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to