QPython请求SSL错误-无可用密码

时间:2019-06-18 08:56:54

标签: python-2.7 python-requests qpython qpython3

我已经尝试使用request.get一段时间了,但是我在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')],)",),))

这是我的代码

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)

有人知道这是怎么回事吗?我以为这会出色地工作。这是qpython特有的问题吗?因为那会解释很多。

1 个答案:

答案 0 :(得分:0)

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"

之后您可以

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

print(r.status_code)