繁体   English   中英

在python中使用请求时,出现以下错误“ TLSV1_ALERT_PROTOCOL_VERSION”。为什么会发生这种情况?

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

到目前为止,这是我的代码。 在Python中使用请求时,出现以下错误:

TLSV1_ALERT_PROTOCOL_VERSION.

为什么会这样呢?

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'

您没有提到使用哪个版本的openSSL,但这很可能是罪魁祸首! 这是一个相当普遍的问题,似乎最好通过全新安装openSSL和Python来解决。

要检查您使用的是哪个版本的openSSL,请转到您的Python终端并输入

import platform
import ssl

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

如果OpenSSL信息作为OpenSSL 0.9.8zh 14 Jan 2016返回,则可能会遇到问题。 在我的Mac上,这将返回OpenSSL 1.0.2j 26 Sep 2016 ,可与我过去使用的其他请求应用程序一起使用。

此时的解决方案可能是卸载openSSL并重新安装它! 但是,您可能还想升级brew的安装,因为它可能无法从去年9月发布的有关OpenSSL 的更新中受益

在查看了网上的一些示例之后,我相信重新安装openssl和升级brew的最直接,最全面的方法(假设没有其他问题)是通过运行:

brew uninstall openssl

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

在最终运行之前,花时间修复brew doctor提出的任何问题

brew install openssl

这将确保您正在运行最新版本的OpenSSL,并应有助于解决该问题!

在此处的补充说明, 升级Homebrew会将所有已安装的软件包更新为最新版本。 如果您的某些其他编码项目依赖于brew版本中现已弃用的软件包,那么这对于您可能不是理想的。 我认为这不会是一个大问题,而只是一个供参考!

如果此OpenSSL卸载对您不起作用,则有其他方法 ,但是我可以想象,如果上述解决方案不起作用,则会出现更大的问题。

希望能帮助到你!

资料来源

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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