---
slug: "Curl,Python,PHPでHTTPS接続する際固まるサイトがあるので、TLS1.2を使わないようにする"
title: "Avoid using TLS 1.2 for certain websites that freeze during HTTPS connections with Curl, Python, and PHP"
description: "\n\n\nAs I wrote in this article http://b.ytyng.com/a-61/, when you make an HTTPS connection with OpenSSL 1.0.1f and attempt to connect using TLS1.2 by issuing a hello, certain sites may freeze in response."
url: "https://www.ytyng.com/en/blog/Curl,Python,PHPでHTTPS接続する際固まるサイトがあるので、TLS1.2を使わないようにする"
publish_date: "2015-06-11T06:28:25Z"
created: "2015-06-11T06:28:25Z"
updated: "2026-02-27T10:42:57.347Z"
categories: ["Linux"]
keywords: ""
featured_image_url: "https://media.ytyng.com/resize/20230812/4e34fb5a2245414fad95d1a2ca59654e.png.webp?width=768"
has_video: false
has_music: false
video_urls: []
music_urls: []
lang: "en"
---

# Avoid using TLS 1.2 for certain websites that freeze during HTTPS connections with Curl, Python, and PHP

<div class="document">


<p>As I wrote in this article <a class="reference external" href="http://b.ytyng.com/a-61/">http://b.ytyng.com/a-61/</a>, when you make an HTTPS connection with OpenSSL 1.0.1f and attempt to connect using TLS1.2 by issuing a hello, certain sites may freeze in response.</p>
<p>(OpenSSL 1.0.1f is the latest default version for Ubuntu 14.04, 15.04, etc. If you are using 1.0.1g, this issue might be resolved)</p>
<p>In such cases, you can avoid the issue by connecting without using TLS1.2.</p>
<p>Here’s how to avoid using TLS1.2 (forcing TLS1.0) with curl, Python, and PHP.</p>
<div class="section" id="curl">
<h3>curl</h3>
<pre class="literal-block">$ curl -vv "https://hoge.example.com/"  # URL is hypothetical
* Hostname was NOT found in DNS cache
*   Trying xxx.xxx.xxx.xxx...
* Connected to hoge.example.com (xxx.xxx.xxx.xxx) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):

It freezes here
</pre>
<p>↓</p>
<p>Not using TLS1.2 (forcing TLS1.0)</p>
<pre class="literal-block">$ curl -vv "https://hoge.example.com/" --tlsv1.0

It doesn't freeze!
</pre>
</div>
<div class="section" id="python3-4-requests">
<h3>python3.4 + requests</h3>
<pre class="literal-block"># import requests
r = requests.get('https://hoge.example.com/')
It freezes!
</pre>
<p>↓ Not using TLS1.2 (forcing TLS1.0)</p>
<pre class="literal-block">import requests

from requests.adapters import HTTPAdapter
from requests.packages.urllib3.poolmanager import PoolManager
import ssl

class MyAdapter(HTTPAdapter):
    def init_poolmanager(self, connections, maxsize, block=False):
        self.poolmanager = PoolManager(
            num_pools=connections,
            maxsize=maxsize,
            block=block,
            ssl_version=ssl.PROTOCOL_TLSv1)

s = requests.Session()
s.mount('https://', MyAdapter())

r = s.get("https://hoge.example.com/")
It doesn't freeze!
</pre>
<p>Reference:</p>
<p>Choosing The SSL Version In Python Requests • Lukasa's Echochamber
<a class="reference external" href="https://lukasa.co.uk/2013/01/Choosing_SSL_Version_In_Requests/">https://lukasa.co.uk/2013/01/Choosing_SSL_Version_In_Requests/</a></p>
</div>
<div class="section" id="php5-6">
<h3>PHP5.6</h3>
<pre class="literal-block">$html = file_get_contents('https://hoge.example.com/');
It freezes!
</pre>
<p>↓ Not using TLS1.2 (forcing TLS1.0)</p>
<pre class="literal-block">$ctx = stream_context_create([
    'ssl' =&gt; [
        'crypto_method' =&gt; STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT,
    ],
]);
$html = file_get_contents('https://hoge.example.com/', false, $ctx);
It doesn't freeze!
</pre>
<p>Reference:</p>
<p>PHP: Changes related to OpenSSL in PHP 5.6.x - Manual
<a class="reference external" href="http://php.net/manual/ja/migration56.openssl.php">http://php.net/manual/ja/migration56.openssl.php</a></p>
</div>
</div>
