<p>Python 2.6中的<code>ssl</code>模块最多只支持TLS 1.0。如果您不希望引入其他依赖项(如您建议的pyOpenSSL),则需要升级到Python 2.7或3.x以获得对较新版本TLS的支持。</p>
<p>要在Python 2.7.9或更高版本中强制使用TLS的特定版本,请使用适当的<a href="http://docs.python-requests.org/en/latest/user/advanced/#example-specific-ssl-version" rel="noreferrer">^{<cd3>} constant</a>。然后,您可以将它与任何允许您提供自己的<code>SSLContext</code>的API一起使用。</p>
<pre><code>import ssl
import urllib2
ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
# set other SSLContext options you might need
response = urllib2.urlopen(url, context=ctx)
</code></pre>
<p>要使用特定的协议版本<em>或更高的</em>(包括将来的版本),请使用<code>ssl.PROTOCOL_SSLv23</code>,然后禁用不想使用的协议版本:</p>
<pre><code>ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
# allow TLS 1.2 and later
ctx.options |= ssl.OP_NO_SSLv2
ctx.options |= ssl.OP_NO_SSLv3
ctx.options |= ssl.OP_NO_TLSv1
ctx.options |= ssl.OP_NO_TLSv1_1
</code></pre>
<p>至于对请求使用自定义<code>SSLContext</code>以强制特定协议版本,<strike><a href="http://docs.python-requests.org/en/latest/api/#requests.request" rel="noreferrer">according to the documentation</a>似乎没有办法这样做</strike>,<a href="http://docs.python-requests.org/en/latest/user/advanced/#example-specific-ssl-version" rel="noreferrer">see the following example from the docs</a>。</p>