mirror of
https://github.com/openvswitch/ovs
synced 2025-09-05 08:45:23 +00:00
python: Fix decoding error when the received data is larger than 4096.
It can only receive 4096 bytes of data each time in jsonrpc, when there are similar and Chinese characters occupy multiple bytes, it may receive half a character, this time the decoding will be abnormal. We need to receive the completed character to decode. Signed-off-by: Guoshuai Li <ligs@dtdream.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import codecs
|
||||
import errno
|
||||
import os
|
||||
import sys
|
||||
@@ -262,6 +262,7 @@ class Connection(object):
|
||||
if self.status:
|
||||
return self.status, None
|
||||
|
||||
decoder = codecs.getincrementaldecoder('utf-8')()
|
||||
while True:
|
||||
if not self.input:
|
||||
error, data = self.stream.recv(4096)
|
||||
@@ -270,7 +271,7 @@ class Connection(object):
|
||||
# data, so we convert it here as soon as possible.
|
||||
if data and not error:
|
||||
try:
|
||||
data = data.decode('utf-8')
|
||||
data = decoder.decode(data)
|
||||
except UnicodeError:
|
||||
error = errno.EILSEQ
|
||||
if error:
|
||||
|
Reference in New Issue
Block a user