1

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.

3
  • ever found a solution to this? running into the same issue. Commented Oct 16, 2019 at 14:42
  • 1
    Joao Pereira turns out requests actually just doesnt work on qpython and they dont seem to have any intention of fixing said issue. if I were you and i just wanted to use requests on my phone, I'd try to use python through linux with the android app UserLAnd. Commented Oct 18, 2019 at 19:25
  • thank you, finally managed to get it working with UserLAnd after several issues with Python 3.8. Commented Oct 20, 2019 at 17:37

1 Answer 1

2

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.