Shirakumo
Shirakumo

Reputation: 192

How to fix 'requests.exceptions.SSLError'

I have read many articles about that but none worked for me. Also, I tried other solutions but still I'm stuck. I have a simple code:

import requests

requests.get('https://s1.wcy.wat.edu.pl/ed1/', verify=False)

After setting verification to False I'm still getting an error:

requests.exceptions.SSLError: HTTPSConnectionPool(host='s1.wcy.wat.edu.pl', port=443): Max retries exceeded with url: /ed1/ (Caused by SSLError(SSLError(1, '[SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:1056)')))

EDIT: Problem solved. For those who has the same problem. Make sure what is your website TLS verion. In my case it was 1.0. Then you must go to /etc/ssl and edit openssl.cnf. At the bottom you have

[system_default_sect]
MinProtocol = TLSv1.2
CipherString = DEFAULT@SECLEVEL=2

Just change 1.2 to 1.0. Worked for me

Upvotes: 11

Views: 22935

Answers (2)

Danarvelini
Danarvelini

Reputation: 36

I had the same issue. I could not make it work with requests, or downgrade/upgrading Python, or using a new cert file in a system env... none of that worked

What worked is this:

import urllib3
from urllib3.util.ssl_ import create_urllib3_context

ctx = create_urllib3_context()
ctx.load_default_certs()
ctx.options |= 0x4  # ssl.OP_LEGACY_SERVER_CONNECT

with urllib3.PoolManager(ssl_context=ctx) as http:
    req = http.request("GET", "your_url")
    data_to_work_with = req .data

That goes through a combination of techniques. But, the main thing in there is this: ctx.load_default_certs() It will load up your default certifications and should help you out.

Upvotes: 1

xilpex
xilpex

Reputation: 3237

I had the same issue. By changing verify=False to verify=ssl.CERT_NONE, I fixed it.

Upvotes: 4

Related Questions