7
이 코드에 문제가 :TMPFILE와 gzip 조합 문제
file = tempfile.TemporaryFile(mode='wrb')
file.write(base64.b64decode(data))
file.flush()
os.fsync(file)
# file.seek(0)
f = gzip.GzipFile(mode='rb', fileobj=file)
print f.read()
은 아무것도 출력하지 않는 이유는 잘 모릅니다. 내가 file.seek의 주석을 경우 오류가 발생합니다
는File "/usr/lib/python2.5/gzip.py", line 263, in _read
self._read_gzip_header()
File "/usr/lib/python2.5/gzip.py", line 162, in _read_gzip_header
magic = self.fileobj.read(2)
IOError: [Errno 9] Bad file descriptor
그냥 내용은이 버전은 잘 작동 :
x = open("test.gzip", 'wb')
x.write(base64.b64decode(data))
x.close()
f = gzip.GzipFile('test.gzip', 'rb')
print f.read()
편집 : WRB의 문제입니다. 초기화 할 때 오류가 발생하지 않습니다. 파이썬 2.5.2.
>>> t = tempfile.TemporaryFile(mode="wrb")
>>> t.write("test")
>>> t.seek(0)
>>> t.read()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: [Errno 9] Bad file descriptor
감사합니다! 그리고 임시 파일은 이것을보고하지 않습니다. 아마 이걸 신고해야할까요? –
@Vojtech R. 그렇습니다. barebones'fhandle = tempfile.TemporaryFile (mode = 'wrb')'를 시도하십시오 (OSError Errno22 잘못된 인수를 반환합니다 ...) – ChristopheD
@ChristopheD. 질문 할 예제를 추가했습니다. .read()까지 오류가 없습니다. –