问题
I am trying to make a request in Python using TLS 1.3 as it is what the site accepts. I use following code:
import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.poolmanager import PoolManager
from requests.packages.urllib3.util import ssl_
CIPHERS = (
'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)
sess = requests.session()
adp = TlsAdapter(ssl.OP_NO_TLSv1_3 | ssl.OP_NO_TLSv1_3)
sess.mount("https://", adapter)
Everything looks fine until here. I started using it to send requests ecc but of pure curiosity I checked deeper and used Wireshark. Here it says the requests go over 1.2 and not 1.3.
Anyone could help me actually to enforce 1.3 and not 1.2? It would be very appreciated. Thanks.
来源:https://stackoverflow.com/questions/57599480/python-requests-use-tls-v-1-3