james beastly
james beastly

Reputation: 51

QPython requests SSL error- no available ciphers

Ive been trying to use requests.get for sometime now but I keep getting this error on Qpython

HTTPSConnectionPool(host='google.com', port=443): 
Max retries exceeded with url:
 / (Caused by SSLError(
    SSLError("bad handshake: Error([('SSL routines', 
'ssl_cipher_list_to_bytes', 'no ciphers available')],)",),))

This is my code

import ssl
import requests 
from requests.adapters import HTTPAdapter 
from requests.packages.urllib3.poolmanager import 
PoolManager 
from requests.packages.urllib3.util import ssl_ 
CIPHERS = ( 'ECDHE-RSA-AES256-GCM-SHA384:ECDHE- 
ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AElS256- 
SHA384: ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA- 
AES128-GCM-SHA256:ECDHE-RSA-AES128- 
SHA256:AES256-SHA' ) 


class TlsAdapter(HTTPAdapter): 
    def __init__(self, ssl_options=0, **kwargs): 
        self.ssl_options = ssl_options 
        super(TlsAdapter, self).__init__(**kwargs) 
    def init_poolmanager(self, *pool_args, **pool_kwargs): 
        ctx = ssl_.create_urllib3_context(ciphers=CIPHERS, 
       cert_reqs=ssl.CERT_REQUIRED, 
      options=self.ssl_options) 
       self.poolmanager = PoolManager(*pool_args, 
       ssl_context=ctx, **pool_kwargs) 

s = requests.session() 
adapter = TlsAdapter() 
s.mount("https://", adapter) 

try: 
    r = s.get('https://google.com') 
    print(r) 
except Exception as e: 
    print(e)

Does anyone know what's going wrong here? I thought this would work splendidly. Is this a problem specific to qpython or not too. Because that would explain a lot.

Upvotes: 1

Views: 5960

Answers (1)

giuliano-macedo
giuliano-macedo

Reputation: 519

Copied from this issue

import requests
requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS = "TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-256-GCM-SHA384:ECDHE:!COMPLEMENTOFDEFAULT"

after that you can

r=requests.get("https://google.com")

print(r.status_code)

Upvotes: 2

Related Questions