简体   繁体   中英

When using requests in python I'm given the following error “TLSV1_ALERT_PROTOCOL_VERSION.” Why might this be happening?

This is my code so far. When using requests in Python I'm given the following error:

TLSV1_ALERT_PROTOCOL_VERSION.

Why might this be happening?

import requests

def lambda_handler(event, context):

     # context = ssl.OPENSSL_VERSION_INFO

     # print(context)
     # if event['session']['application']['applicationId'] != app_id:
     #     raise ValueError("Invalid Application ID")

     token = requests.post(html, data={'apikey': api_key}, auth=(username, password), verify=False)

     print(token.text)
     payload = {'token': token}

     requests.post(html_step_two, data=payload,  verify=False)

     payload = {'token': token, 'workflow_id': workflow_id}
     requests.post(workflow_run, data=payload,  verify=False)

     return 'Hello from Lambda'

You don't mention which version of openSSL you use, but it is likely the culprit! It's a fairly common issue, and one that seems to be best resolved by clean installs of both openSSL and Python.

To check which version of openSSL you are using, go to your Python terminal and type

import platform
import ssl

print("Python info: %s" % (platform.python_version()))
print("OpenSSL info: %s" % (ssl.OPENSSL_VERSION))

If the OpenSSL info is returned as being OpenSSL 0.9.8zh 14 Jan 2016 , you may experience issues. On my mac, this returns OpenSSL 1.0.2j 26 Sep 2016 , which works with other requests applications I've used in the past.

The solution at this point would probably be to uninstall openSSL and reinstall it! However, you would also probably want to upgrade your installation of brew, as it is likely not benefitting from an update released last September concerning OpenSSL.

After looking at a few examples on the web, I believe the most straight-forward and comprehensive way to reinstall openssl and upgrade brew (assuming there are not any other issues) is by running:

brew uninstall openssl

and

brew update && brew upgrade && brew cleanup && brew doctor

taking the time to fix any issues brought up by brew doctor , before finally running

brew install openssl

This will ensure you are running the latest version of OpenSSL, and should help resolve the issue!

A side note here, upgrading Homebrew will update all your installed packages to their latest versions. This may not be ideal for you if some of your other coding projects are dependent on now-deprecated packages included in previous versions of brew . I wouldn't think it to be a large problem, but just an FYI!

If this uninstall of OpenSSL doesn't work for you, there are other ways , but I would imagine there to be larger problems if the above solution doesn't work.

Hope it helps!

Sources

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