We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
TypeError: 'float' object is not iterable (on Twisted dev + Scrapy dev)
This happens on Twisted trunk and with latest Scrapy master.

```
$ 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
```

```
(Pdb) w
  /Users/rolando/Projects/sh/scrapy/scrapy/utils/defer.py(45)mustbe_deferred()
-> result = f(*args, **kw)
  /Users/rolando/Projects/sh/scrapy/scrapy/core/downloader/handlers/__init__.py(65)download_request()
-> return handler.download_request(request, spider)
  /Users/rolando/Projects/sh/scrapy/scrapy/core/downloader/handlers/http11.py(61)download_request()
-> return agent.download_request(request)
  /Users/rolando/Projects/sh/scrapy/scrapy/core/downloader/handlers/http11.py(286)download_request()
-> method, to_bytes(url, encoding='ascii'), headers, bodyproducer)
  /Users/rolando/Projects/gh/twisted/src/twisted/web/client.py(1601)request()
-> parsedURI.originForm)
  /Users/rolando/Projects/gh/twisted/src/twisted/web/client.py(1378)_requestWithEndpoint()
-> d = self._pool.getConnection(key, endpoint)
  /Users/rolando/Projects/gh/twisted/src/twisted/web/client.py(1264)getConnection()
-> return self._newConnection(key, endpoint)
  /Users/rolando/Projects/gh/twisted/src/twisted/web/client.py(1276)_newConnection()
-> return endpoint.connect(factory)
  /Users/rolando/Projects/gh/twisted/src/twisted/internet/endpoints.py(779)connect()
-> EndpointReceiver, self._hostText, portNumber=self._port
  /Users/rolando/Projects/gh/twisted/src/twisted/internet/_resolver.py(174)resolveHostName()
-> onAddress = self._simpleResolver.getHostByName(hostName)
  /Users/rolando/Projects/sh/scrapy/scrapy/resolver.py(21)getHostByName()
-> d = super(CachingThreadedResolver, self).getHostByName(name, timeout)
> /Users/rolando/Projects/gh/twisted/src/twisted/internet/base.py(276)getHostByName()
-> timeoutDelay = sum(timeout)
```

After digging, I found out that the addition of `DNS_TIMEOUT` was not effective at all: https://github.com/scrapy/scrapy/commit/85aa3c7596c6e9c66daaa5503faadd03a16e1d59#diff-92d881d6568986904888f43c885240e2L13

Previously, on Twisted <=16.6.0, the method `getHostByName` was always called with a default timeout: https://github.com/twisted/twisted/blob/twisted-16.6.0/src/twisted/internet/base.py#L565-L573

But now, on Twisted trunk, the method is called without a timeout parameter: https://github.com/twisted/twisted/blob/trunk/src/twisted/internet/_resolver.py#L174

This makes the caching resolver to use the default value `timeout=60.0` which causes the error: https://github.com/twisted/twisted/blob/twisted-16.6.0/src/twisted/internet/base.py#L259-L268

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `scrapy/resolver.py`
Content:
```
1 from twisted.internet import defer
2 from twisted.internet.base import ThreadedResolver
3 
4 from scrapy.utils.datatypes import LocalCache
5 
6 # TODO: cache misses
7 
8 dnscache = LocalCache(10000)
9 
10 class CachingThreadedResolver(ThreadedResolver):
11     def __init__(self, reactor, cache_size, timeout):
12         super(CachingThreadedResolver, self).__init__(reactor)
13         dnscache.limit = cache_size
14         self.timeout = timeout
15 
16     def getHostByName(self, name, timeout=None):
17         if name in dnscache:
18             return defer.succeed(dnscache[name])
19         if not timeout:
20             timeout = self.timeout
21         d = super(CachingThreadedResolver, self).getHostByName(name, timeout)
22         d.addCallback(self._cache_result, name)
23         return d
24 
25     def _cache_result(self, result, name):
26         dnscache[name] = result
27         return result
28
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/scrapy/resolver.py b/scrapy/resolver.py
--- a/scrapy/resolver.py
+++ b/scrapy/resolver.py
@@ -16,8 +16,11 @@
     def getHostByName(self, name, timeout=None):
         if name in dnscache:
             return defer.succeed(dnscache[name])
-        if not timeout:
-            timeout = self.timeout
+        # 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

{"golden_diff": "diff --git a/scrapy/resolver.py b/scrapy/resolver.py\n--- a/scrapy/resolver.py\n+++ b/scrapy/resolver.py\n@@ -16,8 +16,11 @@\n     def getHostByName(self, name, timeout=None):\n         if name in dnscache:\n             return defer.succeed(dnscache[name])\n-        if not timeout:\n-            timeout = self.timeout\n+        # in Twisted<=16.6, getHostByName() is always called with\n+        # a default timeout of 60s (actually passed as (1, 3, 11, 45) tuple),\n+        # so the input argument above is simply overridden\n+        # to enforce Scrapy's DNS_TIMEOUT setting's value\n+        timeout = (self.timeout,)\n         d = super(CachingThreadedResolver, self).getHostByName(name, timeout)\n         d.addCallback(self._cache_result, name)\n         return d\n", "issue": "TypeError: 'float' object is not iterable (on Twisted dev + Scrapy dev)\nThis happens on Twisted trunk and with latest Scrapy master.\r\n\r\n```\r\n$ scrapy shell http://localhost:8081/\r\n2016-12-22 12:52:01 [scrapy.utils.log] INFO: Scrapy 1.2.2 started (bot: scrapybot)\r\n2016-12-22 12:52:01 [scrapy.utils.log] INFO: Overridden settings: {'LOGSTATS_INTERVAL': 0, 'DUPEFILTER_CLASS': 'scrapy.dupefilters.BaseDupeFilter'}\r\n2016-12-22 12:52:01 [scrapy.middleware] INFO: Enabled extensions:\r\n['scrapy.extensions.telnet.TelnetConsole',\r\n 'scrapy.extensions.corestats.CoreStats']\r\n2016-12-22 12:52:01 [scrapy.middleware] INFO: Enabled downloader middlewares:\r\n['scrapy.downloadermiddlewares.httpauth.HttpAuthMiddleware',\r\n 'scrapy.downloadermiddlewares.downloadtimeout.DownloadTimeoutMiddleware',\r\n 'scrapy.downloadermiddlewares.defaultheaders.DefaultHeadersMiddleware',\r\n 'scrapy.downloadermiddlewares.useragent.UserAgentMiddleware',\r\n 'scrapy.downloadermiddlewares.retry.RetryMiddleware',\r\n 'scrapy.downloadermiddlewares.redirect.MetaRefreshMiddleware',\r\n 'scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware',\r\n 'scrapy.downloadermiddlewares.redirect.RedirectMiddleware',\r\n 'scrapy.downloadermiddlewares.cookies.CookiesMiddleware',\r\n 'scrapy.downloadermiddlewares.stats.DownloaderStats']\r\n2016-12-22 12:52:01 [scrapy.middleware] INFO: Enabled spider middlewares:\r\n['scrapy.spidermiddlewares.httperror.HttpErrorMiddleware',\r\n 'scrapy.spidermiddlewares.offsite.OffsiteMiddleware',\r\n 'scrapy.spidermiddlewares.referer.RefererMiddleware',\r\n 'scrapy.spidermiddlewares.urllength.UrlLengthMiddleware',\r\n 'scrapy.spidermiddlewares.depth.DepthMiddleware']\r\n2016-12-22 12:52:01 [scrapy.middleware] INFO: Enabled item pipelines:\r\n[]\r\n2016-12-22 12:52:01 [scrapy.extensions.telnet] DEBUG: Telnet console listening on 127.0.0.1:6023\r\n2016-12-22 12:52:01 [scrapy.core.engine] INFO: Spider opened\r\nTraceback (most recent call last):\r\n  File \"/Users/rolando/miniconda3/envs/dev/bin/scrapy\", line 11, in <module>\r\n    load_entry_point('Scrapy', 'console_scripts', 'scrapy')()\r\n  File \"/Users/rolando/Projects/sh/scrapy/scrapy/cmdline.py\", line 142, in execute\r\n    _run_print_help(parser, _run_command, cmd, args, opts)\r\n  File \"/Users/rolando/Projects/sh/scrapy/scrapy/cmdline.py\", line 88, in _run_print_help\r\n    func(*a, **kw)\r\n  File \"/Users/rolando/Projects/sh/scrapy/scrapy/cmdline.py\", line 149, in _run_command\r\n    cmd.run(args, opts)\r\n  File \"/Users/rolando/Projects/sh/scrapy/scrapy/commands/shell.py\", line 71, in run\r\n    shell.start(url=url)\r\n  File \"/Users/rolando/Projects/sh/scrapy/scrapy/shell.py\", line 47, in start\r\n    self.fetch(url, spider)\r\n  File \"/Users/rolando/Projects/sh/scrapy/scrapy/shell.py\", line 112, in fetch\r\n    reactor, self._schedule, request, spider)\r\n  File \"/Users/rolando/Projects/gh/twisted/src/twisted/internet/threads.py\", line 122, in blockingCallFromThread\r\n    result.raiseException()\r\n  File \"/Users/rolando/Projects/gh/twisted/src/twisted/python/failure.py\", line 372, in raiseException\r\n    raise self.value.with_traceback(self.tb)\r\nTypeError: 'float' object is not iterable\r\n```\r\n\r\n```\r\n(Pdb) w\r\n  /Users/rolando/Projects/sh/scrapy/scrapy/utils/defer.py(45)mustbe_deferred()\r\n-> result = f(*args, **kw)\r\n  /Users/rolando/Projects/sh/scrapy/scrapy/core/downloader/handlers/__init__.py(65)download_request()\r\n-> return handler.download_request(request, spider)\r\n  /Users/rolando/Projects/sh/scrapy/scrapy/core/downloader/handlers/http11.py(61)download_request()\r\n-> return agent.download_request(request)\r\n  /Users/rolando/Projects/sh/scrapy/scrapy/core/downloader/handlers/http11.py(286)download_request()\r\n-> method, to_bytes(url, encoding='ascii'), headers, bodyproducer)\r\n  /Users/rolando/Projects/gh/twisted/src/twisted/web/client.py(1601)request()\r\n-> parsedURI.originForm)\r\n  /Users/rolando/Projects/gh/twisted/src/twisted/web/client.py(1378)_requestWithEndpoint()\r\n-> d = self._pool.getConnection(key, endpoint)\r\n  /Users/rolando/Projects/gh/twisted/src/twisted/web/client.py(1264)getConnection()\r\n-> return self._newConnection(key, endpoint)\r\n  /Users/rolando/Projects/gh/twisted/src/twisted/web/client.py(1276)_newConnection()\r\n-> return endpoint.connect(factory)\r\n  /Users/rolando/Projects/gh/twisted/src/twisted/internet/endpoints.py(779)connect()\r\n-> EndpointReceiver, self._hostText, portNumber=self._port\r\n  /Users/rolando/Projects/gh/twisted/src/twisted/internet/_resolver.py(174)resolveHostName()\r\n-> onAddress = self._simpleResolver.getHostByName(hostName)\r\n  /Users/rolando/Projects/sh/scrapy/scrapy/resolver.py(21)getHostByName()\r\n-> d = super(CachingThreadedResolver, self).getHostByName(name, timeout)\r\n> /Users/rolando/Projects/gh/twisted/src/twisted/internet/base.py(276)getHostByName()\r\n-> timeoutDelay = sum(timeout)\r\n```\r\n\r\nAfter digging, I found out that the addition of `DNS_TIMEOUT` was not effective at all: https://github.com/scrapy/scrapy/commit/85aa3c7596c6e9c66daaa5503faadd03a16e1d59#diff-92d881d6568986904888f43c885240e2L13\r\n\r\nPreviously, on Twisted <=16.6.0, the method `getHostByName` was always called with a default timeout: https://github.com/twisted/twisted/blob/twisted-16.6.0/src/twisted/internet/base.py#L565-L573\r\n\r\nBut now, on Twisted trunk, the method is called without a timeout parameter: https://github.com/twisted/twisted/blob/trunk/src/twisted/internet/_resolver.py#L174\r\n\r\nThis makes the caching resolver to use the default value `timeout=60.0` which causes the error: https://github.com/twisted/twisted/blob/twisted-16.6.0/src/twisted/internet/base.py#L259-L268\n", "before_files": [{"content": "from twisted.internet import defer\nfrom twisted.internet.base import ThreadedResolver\n\nfrom scrapy.utils.datatypes import LocalCache\n\n# TODO: cache misses\n\ndnscache = LocalCache(10000)\n\nclass CachingThreadedResolver(ThreadedResolver):\n    def __init__(self, reactor, cache_size, timeout):\n        super(CachingThreadedResolver, self).__init__(reactor)\n        dnscache.limit = cache_size\n        self.timeout = timeout\n\n    def getHostByName(self, name, timeout=None):\n        if name in dnscache:\n            return defer.succeed(dnscache[name])\n        if not timeout:\n            timeout = self.timeout\n        d = super(CachingThreadedResolver, self).getHostByName(name, timeout)\n        d.addCallback(self._cache_result, name)\n        return d\n\n    def _cache_result(self, result, name):\n        dnscache[name] = result\n        return result\n", "path": "scrapy/resolver.py"}], "after_files": [{"content": "from twisted.internet import defer\nfrom twisted.internet.base import ThreadedResolver\n\nfrom scrapy.utils.datatypes import LocalCache\n\n# TODO: cache misses\n\ndnscache = LocalCache(10000)\n\nclass CachingThreadedResolver(ThreadedResolver):\n    def __init__(self, reactor, cache_size, timeout):\n        super(CachingThreadedResolver, self).__init__(reactor)\n        dnscache.limit = cache_size\n        self.timeout = timeout\n\n    def getHostByName(self, name, timeout=None):\n        if name in dnscache:\n            return defer.succeed(dnscache[name])\n        # in Twisted<=16.6, getHostByName() is always called with\n        # a default timeout of 60s (actually passed as (1, 3, 11, 45) tuple),\n        # so the input argument above is simply overridden\n        # to enforce Scrapy's DNS_TIMEOUT setting's value\n        timeout = (self.timeout,)\n        d = super(CachingThreadedResolver, self).getHostByName(name, timeout)\n        d.addCallback(self._cache_result, name)\n        return d\n\n    def _cache_result(self, result, name):\n        dnscache[name] = result\n        return result\n", "path": "scrapy/resolver.py"}]}