Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the wrong Content-Length in python-server.py for non-ascii charac…
…ters. (#24480) Resolves: #24479 `python-server.py` currently uses `sys.stdin.read` for reading the input, and it receives the length in `str` (utf-8 string). ref: https://docs.python.org/3/library/sys.html On the other "Content-Length" is the size in **bytes**, therefore we should not pass `content_length` to `sys.stdin.read`. For example, `print("こんにちは世界")`'s length is 16 in str, but 30 in bytes. ``` >>> len('print("こんにちは世界")') 16 >>> len('print("こんにちは世界")'.encode()) 30 ``` This PR have two changes. 1. Replace `sys.stdin.read(content_length)` with `sys.stdin.buffer.read(content_length).decode()`. 2. Make `_send_message` calculate "Content-Length" from bytes, not str. By these changes, original issue #24479 can be resolved. ![image](https://github.com/user-attachments/assets/20e72a26-d4ad-4e16-9c5b-ed41055c95d9)
- Loading branch information