We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
empty WARNING message in scrapy.core.downloader.tls (1.1.0rc4/master)
Sometimes I'm getting empty warnings now, on 1.1.0rc4 and master branch.
(at least on rc3 as well)

```
2016-05-07 00:33:46 [scrapy.core.downloader.tls] WARNING: 
2016-05-07 00:33:47 [scrapy.core.downloader.tls] WARNING: 
2016-05-07 00:33:48 [scrapy.core.downloader.tls] WARNING: 
```

It happens in a broad linkcheck crawl; so I couldn't pinpoint what URLs might be responsible for that, at this time. The only other observation so far is, that it doesn't happen on a cache-replayed run (which might be obvious, as there is no TLS there).


--- 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/core/downloader/tls.py`
Content:
```
1 import logging
2 from OpenSSL import SSL
3 
4 
5 logger = logging.getLogger(__name__)
6 
7 METHOD_SSLv3 = 'SSLv3'
8 METHOD_TLS = 'TLS'
9 METHOD_TLSv10 = 'TLSv1.0'
10 METHOD_TLSv11 = 'TLSv1.1'
11 METHOD_TLSv12 = 'TLSv1.2'
12 
13 openssl_methods = {
14     METHOD_TLS:    SSL.SSLv23_METHOD,                   # protocol negotiation (recommended)
15     METHOD_SSLv3:  SSL.SSLv3_METHOD,                    # SSL 3 (NOT recommended)
16     METHOD_TLSv10: SSL.TLSv1_METHOD,                    # TLS 1.0 only
17     METHOD_TLSv11: getattr(SSL, 'TLSv1_1_METHOD', 5),   # TLS 1.1 only
18     METHOD_TLSv12: getattr(SSL, 'TLSv1_2_METHOD', 6),   # TLS 1.2 only
19 }
20 
21 # ClientTLSOptions requires a recent-enough version of Twisted
22 try:
23 
24     # taken from twisted/twisted/internet/_sslverify.py
25     try:
26         from OpenSSL.SSL import SSL_CB_HANDSHAKE_DONE, SSL_CB_HANDSHAKE_START
27     except ImportError:
28         SSL_CB_HANDSHAKE_START = 0x10
29         SSL_CB_HANDSHAKE_DONE = 0x20
30 
31     from twisted.internet._sslverify import (ClientTLSOptions,
32                                              _maybeSetHostNameIndication,
33                                              verifyHostname,
34                                              VerificationError)
35 
36     class ScrapyClientTLSOptions(ClientTLSOptions):
37         # same as Twisted's ClientTLSOptions,
38         # except that VerificationError is caught
39         # and doesn't close the connection
40         def _identityVerifyingInfoCallback(self, connection, where, ret):
41             if where & SSL_CB_HANDSHAKE_START:
42                 _maybeSetHostNameIndication(connection, self._hostnameBytes)
43             elif where & SSL_CB_HANDSHAKE_DONE:
44                 try:
45                     verifyHostname(connection, self._hostnameASCII)
46                 except VerificationError as e:
47                     logger.warning(e)
48 
49 except ImportError:
50     # ImportError should not matter for older Twisted versions
51     # as the above is not used in the fallback ScrapyClientContextFactory
52     pass
53
```
--- 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/core/downloader/tls.py b/scrapy/core/downloader/tls.py
--- a/scrapy/core/downloader/tls.py
+++ b/scrapy/core/downloader/tls.py
@@ -44,7 +44,9 @@
                 try:
                     verifyHostname(connection, self._hostnameASCII)
                 except VerificationError as e:
-                    logger.warning(e)
+                    logger.warning(
+                        'Remote certificate is not valid for hostname "{}"; {}'.format(
+                            self._hostnameASCII, e))
 
 except ImportError:
     # ImportError should not matter for older Twisted versions

{"golden_diff": "diff --git a/scrapy/core/downloader/tls.py b/scrapy/core/downloader/tls.py\n--- a/scrapy/core/downloader/tls.py\n+++ b/scrapy/core/downloader/tls.py\n@@ -44,7 +44,9 @@\n                 try:\n                     verifyHostname(connection, self._hostnameASCII)\n                 except VerificationError as e:\n-                    logger.warning(e)\n+                    logger.warning(\n+                        'Remote certificate is not valid for hostname \"{}\"; {}'.format(\n+                            self._hostnameASCII, e))\n \n except ImportError:\n     # ImportError should not matter for older Twisted versions\n", "issue": "empty WARNING message in scrapy.core.downloader.tls (1.1.0rc4/master)\nSometimes I'm getting empty warnings now, on 1.1.0rc4 and master branch.\n(at least on rc3 as well)\n\n```\n2016-05-07 00:33:46 [scrapy.core.downloader.tls] WARNING: \n2016-05-07 00:33:47 [scrapy.core.downloader.tls] WARNING: \n2016-05-07 00:33:48 [scrapy.core.downloader.tls] WARNING: \n```\n\nIt happens in a broad linkcheck crawl; so I couldn't pinpoint what URLs might be responsible for that, at this time. The only other observation so far is, that it doesn't happen on a cache-replayed run (which might be obvious, as there is no TLS there).\n\n", "before_files": [{"content": "import logging\nfrom OpenSSL import SSL\n\n\nlogger = logging.getLogger(__name__)\n\nMETHOD_SSLv3 = 'SSLv3'\nMETHOD_TLS = 'TLS'\nMETHOD_TLSv10 = 'TLSv1.0'\nMETHOD_TLSv11 = 'TLSv1.1'\nMETHOD_TLSv12 = 'TLSv1.2'\n\nopenssl_methods = {\n    METHOD_TLS:    SSL.SSLv23_METHOD,                   # protocol negotiation (recommended)\n    METHOD_SSLv3:  SSL.SSLv3_METHOD,                    # SSL 3 (NOT recommended)\n    METHOD_TLSv10: SSL.TLSv1_METHOD,                    # TLS 1.0 only\n    METHOD_TLSv11: getattr(SSL, 'TLSv1_1_METHOD', 5),   # TLS 1.1 only\n    METHOD_TLSv12: getattr(SSL, 'TLSv1_2_METHOD', 6),   # TLS 1.2 only\n}\n\n# ClientTLSOptions requires a recent-enough version of Twisted\ntry:\n\n    # taken from twisted/twisted/internet/_sslverify.py\n    try:\n        from OpenSSL.SSL import SSL_CB_HANDSHAKE_DONE, SSL_CB_HANDSHAKE_START\n    except ImportError:\n        SSL_CB_HANDSHAKE_START = 0x10\n        SSL_CB_HANDSHAKE_DONE = 0x20\n\n    from twisted.internet._sslverify import (ClientTLSOptions,\n                                             _maybeSetHostNameIndication,\n                                             verifyHostname,\n                                             VerificationError)\n\n    class ScrapyClientTLSOptions(ClientTLSOptions):\n        # same as Twisted's ClientTLSOptions,\n        # except that VerificationError is caught\n        # and doesn't close the connection\n        def _identityVerifyingInfoCallback(self, connection, where, ret):\n            if where & SSL_CB_HANDSHAKE_START:\n                _maybeSetHostNameIndication(connection, self._hostnameBytes)\n            elif where & SSL_CB_HANDSHAKE_DONE:\n                try:\n                    verifyHostname(connection, self._hostnameASCII)\n                except VerificationError as e:\n                    logger.warning(e)\n\nexcept ImportError:\n    # ImportError should not matter for older Twisted versions\n    # as the above is not used in the fallback ScrapyClientContextFactory\n    pass\n", "path": "scrapy/core/downloader/tls.py"}], "after_files": [{"content": "import logging\nfrom OpenSSL import SSL\n\n\nlogger = logging.getLogger(__name__)\n\nMETHOD_SSLv3 = 'SSLv3'\nMETHOD_TLS = 'TLS'\nMETHOD_TLSv10 = 'TLSv1.0'\nMETHOD_TLSv11 = 'TLSv1.1'\nMETHOD_TLSv12 = 'TLSv1.2'\n\nopenssl_methods = {\n    METHOD_TLS:    SSL.SSLv23_METHOD,                   # protocol negotiation (recommended)\n    METHOD_SSLv3:  SSL.SSLv3_METHOD,                    # SSL 3 (NOT recommended)\n    METHOD_TLSv10: SSL.TLSv1_METHOD,                    # TLS 1.0 only\n    METHOD_TLSv11: getattr(SSL, 'TLSv1_1_METHOD', 5),   # TLS 1.1 only\n    METHOD_TLSv12: getattr(SSL, 'TLSv1_2_METHOD', 6),   # TLS 1.2 only\n}\n\n# ClientTLSOptions requires a recent-enough version of Twisted\ntry:\n\n    # taken from twisted/twisted/internet/_sslverify.py\n    try:\n        from OpenSSL.SSL import SSL_CB_HANDSHAKE_DONE, SSL_CB_HANDSHAKE_START\n    except ImportError:\n        SSL_CB_HANDSHAKE_START = 0x10\n        SSL_CB_HANDSHAKE_DONE = 0x20\n\n    from twisted.internet._sslverify import (ClientTLSOptions,\n                                             _maybeSetHostNameIndication,\n                                             verifyHostname,\n                                             VerificationError)\n\n    class ScrapyClientTLSOptions(ClientTLSOptions):\n        # same as Twisted's ClientTLSOptions,\n        # except that VerificationError is caught\n        # and doesn't close the connection\n        def _identityVerifyingInfoCallback(self, connection, where, ret):\n            if where & SSL_CB_HANDSHAKE_START:\n                _maybeSetHostNameIndication(connection, self._hostnameBytes)\n            elif where & SSL_CB_HANDSHAKE_DONE:\n                try:\n                    verifyHostname(connection, self._hostnameASCII)\n                except VerificationError as e:\n                    logger.warning(\n                        'Remote certificate is not valid for hostname \"{}\"; {}'.format(\n                            self._hostnameASCII, e))\n\nexcept ImportError:\n    # ImportError should not matter for older Twisted versions\n    # as the above is not used in the fallback ScrapyClientContextFactory\n    pass\n", "path": "scrapy/core/downloader/tls.py"}]}