I need your help please. We have a script that it is necessary to run in Linux server with python 3.8
I have problem when i try to run the script to search GZIP File
This is the function
def read_file(file):
GZIP_MAGIC_NUMBER = “0x1f8b” #may not work everytime, but .gz files should have those first 2 bytes…
f = open(file)
if f.read(2).encode( “utf-8”) == GZIP_MAGIC_NUMBER: #check if compressed
f.close()
f = gzip.GzipFile(file, “r”) #open compressed file
else:
f.close()
f = open(file, “r”) #open not compressed file
return f
And the error is the following:
$ python3 findHHIvan.py -s 86VRPQ2GD6EE6M0G2GLY0M -f message.log.2024-05-06_1128.2024-05-06_1131.gz -d /cxpslogs/powerBI/pruebasTransaction
searching in specified directories…
first search
file /cxpslogs/powerBI/pruebasTransaction/message.log.2024-05-06_1128.2024-05-06_1131.gz |
Traceback (most recent call last):
File “findHHIvan.py”, line 660, in
found = search(searching_criterias, files, found)
File “findHHIvan.py”, line 315, in search
arch = read_file(file)
File “findHHIvan.py”, line 127, in read_file
if f.read(2).encode( “utf-8”) == GZIP_MAGIC_NUMBER:#check if compressed
File “/opt/rh/rh-python38/root/usr/lib64/python3.8/codecs.py”, line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0your text
x8b in position 1: invalid start byte
I need to run the python script and the GZ file compressed can be open to work.
Thanks you
Hector is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.