Author da
Recipients da
Date 2018-03-10.00:46:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The Python documentation states that if the GzipFile can't determine a filename from `fileobj` it'll use an empty string and won't be included in the header. Unfortunately, this doesn't work for SpooledTemporaryFile which has a `name` attribute but doesn't set it initially. The result is a crash.

To reproduce

import gzip
import tempfile

with tempfile.SpooledTemporaryFile() as fd:
    with gzip.GzipFile(mode='wb', fileobj=fd) as gz:

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/Users/diegoargueta/.pyenv/versions/2.7.14/lib/python2.7/", line 136, in __init__
  File "/Users/diegoargueta/.pyenv/versions/2.7.14/lib/python2.7/", line 170, in _write_gzip_header
    fname = os.path.basename(
  File "/Users/diegoargueta/.pyenv/versions/gds27/lib/python2.7/", line 114, in basename
    i = p.rfind('/') + 1
AttributeError: 'NoneType' object has no attribute 'rfind'

This doesn't happen on Python 3.6, where the null filename is handled properly. I've attached a patch file that fixed the issue for me.
Date User Action Args
2018-03-10 00:46:11dasetrecipients: + da
2018-03-10 00:46:10dasetmessageid: <>
2018-03-10 00:46:10dalinkissue33038 messages
2018-03-10 00:46:10dacreate