Skip to content Skip to sidebar Skip to footer

Python Requests : SSL Error During Requests?

I'm learning API requests using python requests for personal interest. I'm trying to simply download the URL 'https://live.euronext.com/fr/product/equities/fr0000120578-xpar/'. It

Solution 1:

I finally managed to find the issue, thanks to https://github.com/psf/requests/issues/4775

import requests
import ssl
from urllib3 import poolmanager

url = 'https://live.euronext.com/fr/product/equities/FR0000120271-XPAR'

class TLSAdapter(requests.adapters.HTTPAdapter):

    def init_poolmanager(self, connections, maxsize, block=False):
        """Create and initialize the urllib3 PoolManager."""
        ctx = ssl.create_default_context()
        ctx.set_ciphers('DEFAULT@SECLEVEL=1')
        self.poolmanager = poolmanager.PoolManager(
                num_pools=connections,
                maxsize=maxsize,
                block=block,
                ssl_version=ssl.PROTOCOL_TLS,
                ssl_context=ctx)

session = requests.session()
session.mount('https://', TLSAdapter())
res = session.get(url)
print(res)

And the output was <Response [200]> !


Solution 2:

A bit shorter version of pyOliv's solution which worked for me:

import requests
import ssl

url = 'https://www.tauron-dystrybucja.pl/'

class TLSAdapter(requests.adapters.HTTPAdapter):

    def init_poolmanager(self, *args, **kwargs):
        ctx = ssl.create_default_context()
        ctx.set_ciphers('DEFAULT@SECLEVEL=1')
        kwargs['ssl_context'] = ctx
        return super(TLSAdapter, self).init_poolmanager(*args, **kwargs)

session = requests.session()
session.mount('https://', TLSAdapter())
res = session.get(url)
print(res)

Post a Comment for "Python Requests : SSL Error During Requests?"