|
发表于 2021-2-25 09:32:47
|
显示全部楼层
请教如何解决的 ,我也遇到类似问题。 读取的是从LINUX 的FTP服务器上 下载的 gzip文件( .tar.gz文件) 读取到文件末尾行时 就报错。
代码段如下:
for temp_name in lst_path:
lst_path1 =tar_path + temp_name
oldFileName = gzip.open(lst_path1, 'r+') # 不解压直接读取 tar.gz 文件
#oldFileName = open(lst_path1, 'r+', encoding='utf-8') # 读取 txt 的 MML 结果文件
Textline=[1]
while not Textline=="":
print(Textline )
Textline = bytes.decode(oldFileName.readline(),encoding="utf-8") # 不解压直接读取 tar.gz 文件,并转码 #出错行
#print(Textline)
Textline1 = ''.join(Textline).strip()
print(Textline1)
if Textline1== "" or (not "命令-----" in Textline1):
continue
FUNC = LST_DICT[Textline1]
FUNC(Textline1, Textline[7:].replace(" ", "_").replace(":;\r\n", "").lower())
报错如下:
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.2.3\helpers\pydev\pydevd.py", line 1580, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.2.3\helpers\pydev\pydevd.py", line 964, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.2.3\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/zhangweili/PycharmProjects/LSTNR/datafx_js_v2.py", line 1438, in <module>
Textline = bytes.decode(oldFileName.readline(),encoding="utf-8") # 不解压直接读取 tar.gz 文件,并转码
File "C:\Users\zhangweili\AppData\Local\Programs\Python\Python37\lib\gzip.py", line 374, in readline
return self._buffer.readline(size)
File "C:\Users\zhangweili\AppData\Local\Programs\Python\Python37\lib\_compression.py", line 68, in readinto
data = self.read(len(byte_view))
File "C:\Users\zhangweili\AppData\Local\Programs\Python\Python37\lib\gzip.py", line 463, in read
if not self._read_gzip_header():
File "C:\Users\zhangweili\AppData\Local\Programs\Python\Python37\lib\gzip.py", line 411, in _read_gzip_header
raise OSError('Not a gzipped file (%r)' % magic)
OSError: Not a gzipped file (b'\x99\x12')
|
|