thinker0 commented on a change in pull request #3580:
URL: https://github.com/apache/incubator-heron/pull/3580#discussion_r459174401
##########
File path: heron/shell/src/python/utils.py
##########
@@ -135,21 +135,22 @@ def read_chunk(filename, offset=-1, length=-1,
escape_data=False):
if length == -1:
length = fstat.st_size - offset
- with open(filename, "r") as fp:
+ with open(filename, "rb") as fp:
fp.seek(offset)
try:
data = fp.read(length)
except IOError:
return {}
if data:
- data = _escape_data(data) if escape_data else data
+ # use permissive decoding and escaping if escape_data is set, otherwise
use strict decoding
+ data = _escape_data(data) if escape_data else data.decode()
return dict(offset=offset, length=len(data), data=data)
return dict(offset=offset, length=0)
def _escape_data(data):
- return escape(data.decode('utf8', 'replace'))
Review comment:
```
with open(filename, "r") as fp:
```
If you read it as binary, escape doesn't work.
```
[E 200723 10:40:39 web:1407] Uncaught exception GET
/filedata/./log-files/container_46_pulsar-prod-4_96.log.0?offset=4191685&length=50000
(10.128.139.55)
HTTPServerRequest(protocol='http',
host='shared-aurora-044-ladp-jp2p-prod:31516', method='GET',
uri='/filedata/./log-files/container_46_pulsar-prod-4_96.log.0?offset=4191685&length=50000',
version='HTTP/1.1', remote_ip='10.128.139.55', headers={'Connection': 'close',
'Host': 'shared-aurora-044-ladp-jp2p-prod:31516', 'Accept-Encoding': 'gzip'})
Traceback (most recent call last):
File
"/var/lib/mesos/slaves/9a7b96a9-a670-48e3-bedf-051a91ac5a9b-S251/frameworks/c663397e-a472-43bd-92dd-d97027fcf6ce-0000/executors/thermos-www-release-heron-system-access-es-others-46-02c80d1d-6257-4b42-829c-6fafbed25b8d/runs/8597c5be-55d4-4b8b-9e2e-2b8faddc3372/sandbox/.pex/installed_wheels/ba642ca162d5bf8bbf2fad77d02edcf2a3188eb8/tornado-4.0.2-cp36-cp36m-linux_x86_64.whl/tornado/web.py",
line 1288, in _stack_context_handle_exception
raise_exc_info((type, value, traceback))
File "<string>", line 3, in raise_exc_info
File
"/var/lib/mesos/slaves/9a7b96a9-a670-48e3-bedf-051a91ac5a9b-S251/frameworks/c663397e-a472-43bd-92dd-d97027fcf6ce-0000/executors/thermos-www-release-heron-system-access-es-others-46-02c80d1d-6257-4b42-829c-6fafbed25b8d/runs/8597c5be-55d4-4b8b-9e2e-2b8faddc3372/sandbox/.pex/installed_wheels/ba642ca162d5bf8bbf2fad77d02edcf2a3188eb8/tornado-4.0.2-cp36-cp36m-linux_x86_64.whl/tornado/web.py",
line 1475, in wrapper
result = method(self, *args, **kwargs)
File
"/var/lib/mesos/slaves/9a7b96a9-a670-48e3-bedf-051a91ac5a9b-S251/frameworks/c663397e-a472-43bd-92dd-d97027fcf6ce-0000/executors/thermos-www-release-heron-system-access-es-others-46-02c80d1d-6257-4b42-829c-6fafbed25b8d/runs/8597c5be-55d4-4b8b-9e2e-2b8faddc3372/sandbox/.pex/code/ca989480a7444b1c46f32b02147ba41568922357/heron/shell/src/python/handlers/filedatahandler.py",
line 50, in get
data = utils.read_chunk(path, offset=offset, length=length,
escape_data=True)
File
"/var/lib/mesos/slaves/9a7b96a9-a670-48e3-bedf-051a91ac5a9b-S251/frameworks/c663397e-a472-43bd-92dd-d97027fcf6ce-0000/executors/thermos-www-release-heron-system-access-es-others-46-02c80d1d-6257-4b42-829c-6fafbed25b8d/runs/8597c5be-55d4-4b8b-9e2e-2b8faddc3372/sandbox/.pex/code/ca989480a7444b1c46f32b02147ba41568922357/heron/shell/src/python/utils.py",
line 147, in read_chunk
data = _escape_data(data) if escape_data else data.decode()
File
"/var/lib/mesos/slaves/9a7b96a9-a670-48e3-bedf-051a91ac5a9b-S251/frameworks/c663397e-a472-43bd-92dd-d97027fcf6ce-0000/executors/thermos-www-release-heron-system-access-es-others-46-02c80d1d-6257-4b42-829c-6fafbed25b8d/runs/8597c5be-55d4-4b8b-9e2e-2b8faddc3372/sandbox/.pex/code/ca989480a7444b1c46f32b02147ba41568922357/heron/shell/src/python/utils.py",
line 153, in _escape_data
return escape(data)
File "/usr/lib64/python3.6/xml/sax/saxutils.py", line 27, in escape
data = data.replace("&", "&")
TypeError: a bytes-like object is required, not 'str'
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]