# Buggy code
def getHostByName(self, name, timeout=None):
    if name in dnscache:
        return defer.succeed(dnscache[name])
    if not timeout:
        timeout = self.timeout
    d = super(CachingThreadedResolver, self).getHostByName(name, timeout)
    d.addCallback(self._cache_result, name)
    return d


# Traceback (TypeError)
$ scrapy shell http://localhost:8081/
2016-12-22 12:52:01 [scrapy.utils.log] INFO: Scrapy 1.2.2 started (bot: scrapybot)
2016-12-22 12:52:01 [scrapy.utils.log] INFO: Overridden settings: {'LOGSTATS_INTERVAL': 0, 'DUPEFILTER_CLASS': 'scrapy.dupefilters.BaseDupeFilter'}
2016-12-22 12:52:01 [scrapy.middleware] INFO: Enabled extensions:
['scrapy.extensions.telnet.TelnetConsole',
'scrapy.extensions.corestats.CoreStats']
2016-12-22 12:52:01 [scrapy.middleware] INFO: Enabled downloader middlewares:
['scrapy.downloadermiddlewares.httpauth.HttpAuthMiddleware',
'scrapy.downloadermiddlewares.downloadtimeout.DownloadTimeoutMiddleware',
'scrapy.downloadermiddlewares.defaultheaders.DefaultHeadersMiddleware',
'scrapy.downloadermiddlewares.useragent.UserAgentMiddleware',
'scrapy.downloadermiddlewares.retry.RetryMiddleware',
'scrapy.downloadermiddlewares.redirect.MetaRefreshMiddleware',
'scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware',
'scrapy.downloadermiddlewares.redirect.RedirectMiddleware',
'scrapy.downloadermiddlewares.cookies.CookiesMiddleware',
'scrapy.downloadermiddlewares.stats.DownloaderStats']
2016-12-22 12:52:01 [scrapy.middleware] INFO: Enabled spider middlewares:
['scrapy.spidermiddlewares.httperror.HttpErrorMiddleware',
'scrapy.spidermiddlewares.offsite.OffsiteMiddleware',
'scrapy.spidermiddlewares.referer.RefererMiddleware',
'scrapy.spidermiddlewares.urllength.UrlLengthMiddleware',
'scrapy.spidermiddlewares.depth.DepthMiddleware']
2016-12-22 12:52:01 [scrapy.middleware] INFO: Enabled item pipelines:
[]
2016-12-22 12:52:01 [scrapy.extensions.telnet] DEBUG: Telnet console listening on 127.0.0.1:6023
2016-12-22 12:52:01 [scrapy.core.engine] INFO: Spider opened
Traceback (most recent call last):
File "/Users/rolando/miniconda3/envs/dev/bin/scrapy", line 11, in <module>
load_entry_point('Scrapy', 'console_scripts', 'scrapy')()
File "/Users/rolando/Projects/sh/scrapy/scrapy/cmdline.py", line 142, in execute
_run_print_help(parser, _run_command, cmd, args, opts)
File "/Users/rolando/Projects/sh/scrapy/scrapy/cmdline.py", line 88, in _run_print_help
func(*a, **kw)
File "/Users/rolando/Projects/sh/scrapy/scrapy/cmdline.py", line 149, in _run_command
cmd.run(args, opts)
File "/Users/rolando/Projects/sh/scrapy/scrapy/commands/shell.py", line 71, in run
shell.start(url=url)
File "/Users/rolando/Projects/sh/scrapy/scrapy/shell.py", line 47, in start
self.fetch(url, spider)
File "/Users/rolando/Projects/sh/scrapy/scrapy/shell.py", line 112, in fetch
reactor, self._schedule, request, spider)
File "/Users/rolando/Projects/gh/twisted/src/twisted/internet/threads.py", line 122, in blockingCallFromThread
result.raiseException()
File "/Users/rolando/Projects/gh/twisted/src/twisted/python/failure.py", line 372, in raiseException
raise self.value.with_traceback(self.tb)
TypeError: 'float' object is not iterable

# Fixed code
def getHostByName(self, name, timeout=None):
    if name in dnscache:
        return defer.succeed(dnscache[name])
    # in Twisted<=16.6, getHostByName() is always called with
    # a default timeout of 60s (actually passed as (1, 3, 11, 45) tuple),
    # so the input argument above is simply overridden
    # to enforce Scrapy's DNS_TIMEOUT setting's value
    timeout = (self.timeout,)
    d = super(CachingThreadedResolver, self).getHostByName(name, timeout)
    d.addCallback(self._cache_result, name)
    return d