# Buggy code
def _get_sitemap_body(self, response):
    """Return the sitemap body contained in the given response,
    or None if the response is not a sitemap.
    """
    if isinstance(response, XmlResponse):
        return response.body
    elif is_gzipped(response):
        return gunzip(response.body)
    elif response.url.endswith(".xml"):
        return response.body
    elif response.url.endswith(".xml.gz"):
        return gunzip(response.body)


# Traceback (AttributeError)
$ scrapy runspider spider.py
2016-11-09 15:53:10 [scrapy] INFO: Scrapy 1.2.1 started (bot: scrapybot)
(...)
2016-11-09 15:53:10 [scrapy] INFO: Spider opened
2016-11-09 15:53:10 [scrapy] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2016-11-09 15:53:10 [scrapy] DEBUG: Telnet console listening on 127.0.0.1:6023
2016-11-09 15:53:11 [scrapy] DEBUG: Crawled (200) <GET http://www.newegg.com/Siteindex_USA.xml> (referer: None)
2016-11-09 15:53:11 [scrapy] DEBUG: Crawled (200) <GET http://www.newegg.com/Sitemap/USA/newegg_sitemap_store01.xml.gz> (referer: http://www.newegg.com/Siteindex_USA.xml)
2016-11-09 15:53:11 [scrapy] ERROR: Spider error processing <GET http://www.newegg.com/Sitemap/USA/newegg_sitemap_store01.xml.gz> (referer: http://www.newegg.com/Siteindex_USA.xml)
Traceback (most recent call last):
File "/home/paul/.virtualenvs/scrapy12/local/lib/python2.7/site-packages/scrapy/utils/defer.py", line 102, in iter_errback
yield next(it)
File "/home/paul/.virtualenvs/scrapy12/local/lib/python2.7/site-packages/scrapy/spidermiddlewares/offsite.py", line 29, in process_spider_output
for x in result:
File "/home/paul/.virtualenvs/scrapy12/local/lib/python2.7/site-packages/scrapy/spidermiddlewares/referer.py", line 22, in <genexpr>
return (_set_referer(r) for r in result or ())
File "/home/paul/.virtualenvs/scrapy12/local/lib/python2.7/site-packages/scrapy/spidermiddlewares/urllength.py", line 37, in <genexpr>
return (r for r in result or () if _filter(r))
File "/home/paul/.virtualenvs/scrapy12/local/lib/python2.7/site-packages/scrapy/spidermiddlewares/depth.py", line 58, in <genexpr>
return (r for r in result or () if _filter(r))
File "/home/paul/.virtualenvs/scrapy12/local/lib/python2.7/site-packages/scrapy/spiders/sitemap.py", line 44, in _parse_sitemap
s = Sitemap(body)
File "/home/paul/.virtualenvs/scrapy12/local/lib/python2.7/site-packages/scrapy/utils/sitemap.py", line 17, in __init__
rt = self._root.tag
AttributeError: 'NoneType' object has no attribute 'tag'

# Fixed code
def _get_sitemap_body(self, response):
    """Return the sitemap body contained in the given response,
    or None if the response is not a sitemap.
    """
    if isinstance(response, XmlResponse):
        return response.body
    elif gzip_magic_number(response):
        return gunzip(response.body)
    # actual gzipped sitemap files are decompressed above ;
    # if we are here (response body is not gzipped)
    # and have a response for .xml.gz,
    # it usually means that it was already gunzipped
    # by HttpCompression middleware,
    # the HTTP response being sent with "Content-Encoding: gzip"
    # without actually being a .xml.gz file in the first place,
    # merely XML gzip-compressed on the fly,
    # in other word, here, we have plain XML
    elif response.url.endswith(".xml") or response.url.endswith(".xml.gz"):
        return response.body