# SSL Handshake Failure with Python 3.11 and 3.12

**URL:** <https://discuss.python.org/t/ssl-handshake-failure-with-python-3-11-and-3-12/71289>\
**Category:** Python Help\
**Tags:** help\
**Created:** [November 15, 2024, 3:37pm UTC](https://discuss.python.org/t/ssl-handshake-failure-with-python-3-11-and-3-12/71289 "2024-11-15T15:37:19Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Samanth\_m](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@Samanth\_m](https://discuss.python.org/u/Samanth_m)\
**Post date:** [November 15, 2024, 3:37pm UTC](https://discuss.python.org/t/ssl-handshake-failure-with-python-3-11-and-3-12/71289/1 "2024-11-15T15:37:19Z")

</div>

Hi everyone,

I’m encountering an SSL handshake failure when upgrading my Python application from versions 3.8 and 3.9 to 3.11 and 3.12. The server side uses TLS 1.2. Here are the errors I’m seeing:

Python 3.12: [SSL: SSLV3\_ALERT\_HANDSHAKE\_FAILURE] sslv3 alert handshake failure (\_ssl.c:1000)  
Python 3.11: [SSL: SSLV3\_ALERT\_HANDSHAKE\_FAILURE] sslv3 alert handshake failure (\_ssl.c:1006)

I suspect this is due to a mismatch between the server and client protocols. Below is a snippet of my code:

import smtplib  
import http.client  
import base64  
import urllib  
import os

host = “xyzabc.coom”  
path = “get/FileDetails”

path = ‘XYZ/XYZ’

context = ssl.create\_default\_context()  
context.minimum\_version = ssl.TLSVersion.TLSv1\_2  
context.maximum\_version = ssl.TLSVersion.TLSv1\_2

conn = http.client.HTTPSConnection(host, context=context)  
conn.request(method=“GET”, url=path, headers=headers)  
response = conn.getresponse()  
conn.close()

I’ve tried enforcing TLS 1.2 in my code, but the issue persists. Any suggestions on how to resolve this?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![barry-scott](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@barry-scott](https://discuss.python.org/u/barry-scott)\
**Post date:** [November 15, 2024, 6:47pm UTC](https://discuss.python.org/t/ssl-handshake-failure-with-python-3-11-and-3-12/71289/2 "2024-11-15T18:47:00Z")

</div>

What OS are you using? It could be a configuration of the TLS that is the issue.  
If you are ona linux or BSD system then you can test with the openssl command.

---

<div class="post-metadata">

**Author:** ![Samanth\_m](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@Samanth\_m](https://discuss.python.org/u/Samanth_m)\
**Post date:** [November 15, 2024, 9:40pm UTC](https://discuss.python.org/t/ssl-handshake-failure-with-python-3-11-and-3-12/71289/3 "2024-11-15T21:40:19Z")

</div>

I am running on windows

---

<div class="post-metadata">

**Author:** ![barry-scott](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@barry-scott](https://discuss.python.org/u/barry-scott)\
**Post date:** [November 16, 2024, 7:57am UTC](https://discuss.python.org/t/ssl-handshake-failure-with-python-3-11-and-3-12/71289/4 "2024-11-16T07:57:37Z")

</div>

Can you use a browser to access the page?

> [@Samanth\_m](#):
>
> context.maximum\_version = ssl.TLSVersion.TLSv1\_2

Doesn’t this prevent TLS v1.3? A lot of sites a TLS 1.3 these days.

---

<div class="post-metadata">

**Author:** ![Samanth\_m](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@Samanth\_m](https://discuss.python.org/u/Samanth_m)\
**Post date:** [November 18, 2024, 2:00pm UTC](https://discuss.python.org/t/ssl-handshake-failure-with-python-3-11-and-3-12/71289/5 "2024-11-18T14:00:47Z")

</div>

I tried to enforce python 3.11 to use TLS 1.2 cuz the server also having same

---

<div class="post-metadata">

**Author:** ![barry-scott](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@barry-scott](https://discuss.python.org/u/barry-scott)\
**Post date:** [November 18, 2024, 6:17pm UTC](https://discuss.python.org/t/ssl-handshake-failure-with-python-3-11-and-3-12/71289/6 "2024-11-18T18:17:15Z")

</div>

Try removing the restrictions are see if you can connect.  
Its usually a bad idea to prevent more secure TLS from being used.

---

<div class="post-metadata">

**Author:** ![Samanth\_m](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@Samanth\_m](https://discuss.python.org/u/Samanth_m)\
**Post date:** [November 18, 2024, 9:02pm UTC](https://discuss.python.org/t/ssl-handshake-failure-with-python-3-11-and-3-12/71289/7 "2024-11-18T21:02:21Z")

</div>

I am facing same error. Previously i don’t have it.

---

<div class="post-metadata">

**Author:** ![barry-scott](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@barry-scott](https://discuss.python.org/u/barry-scott)\
**Post date:** [November 18, 2024, 9:58pm UTC](https://discuss.python.org/t/ssl-handshake-failure-with-python-3-11-and-3-12/71289/8 "2024-11-18T21:58:09Z")

</div>

Is the server you are connecting to on the internet?  
If so I could do a test connection.

---

<div class="post-metadata">

**Author:** ![Samanth\_m](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@Samanth\_m](https://discuss.python.org/u/Samanth_m)\
**Post date:** [November 18, 2024, 10:09pm UTC](https://discuss.python.org/t/ssl-handshake-failure-with-python-3-11-and-3-12/71289/9 "2024-11-18T22:09:57Z")

</div>

its not in internet.  
With python 3.8 , 3.9 its working fine.

Below is the actual code

conn = http.client.HTTPSConnection(host)  
conn.request(method=“GET”, url=path, headers=headers)  
response = conn.getresponse()

---

<div class="post-metadata">

**Author:** ![Samanth\_m](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@Samanth\_m](https://discuss.python.org/u/Samanth_m)\
**Post date:** [November 25, 2024, 1:50pm UTC](https://discuss.python.org/t/ssl-handshake-failure-with-python-3-11-and-3-12/71289/10 "2024-11-25T13:50:01Z")

</div>

Issue fixed after setting cipher context to supported server protocol  
did following

ctx = ssl.create\_default\_context() # This code configures an SSL context with a specific set of secure ciphers, ensuring strong encryption for secure communications. It excludes weaker ciphers to enhance security.  
ctx.set\_ciphers(‘@SECLEVEL=2:ECDH+AESGCM:ECDH+CHACHA20:ECDH+AES:DHE+AES:AESGCM:!aNULL:!eNULL:!aDSS:!SHA1:!AESCCM:!PSK’)
