简体   繁体   中英

TLSV1_ALERT_PROTOCOL_VERSION with python requests package

I am using the request package as

url = 'https://jobregister.aas.org'
page = requests.get(url) 

but this leads to the following error

requests.exceptions.ConnectionError: 
HTTPSConnectionPool(host=url, port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError(1, u'[SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590)'),))

does anybody know what is causing this?

EDIT: I noticed that this error only happens with for the url above. Other urls don't show this issue?

I believe that your issue is that '/' does not want to establish communication with your Requests via TLS v1.0 .

I did encounter identical exception a couple days ago when I was using Python2.7.10 and OpenSSL 1.0.2l on my local machine. This issue was resolved by upgrading to Python2.7.13 . I haven't investigated in depth what is causation of Requests raising this exception yet.

In my case the server was configured with tls1.1 only. The solution was using SSLAdapter.

import requests, ssl
from requests_toolbelt import SSLAdapter

with requests.Session() as _sess:
    _sess.mount("https://", SSLAdapter(ssl.PROTOCOL_TLSv1_1))
    res = _sess.post(url_endpoint, **kwargs)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM