到目前为止,这是我的代码。在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'
答案 0 :(得分:1)
您没有提到您使用的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的安装,因为它可能不是benefitting from an update released last September有关OpenSSL的。
在查看网络上的一些示例后,我认为重新安装openssl
和升级brew
(假设没有任何其他问题)的最直接和最全面的方法是运行:
brew uninstall openssl
和
brew update && brew upgrade && brew cleanup && brew doctor
在最终运行
之前,花时间解决brew doctor
提出的任何问题
brew install openssl
这将确保您运行最新版本的OpenSSL,并且应该有助于解决问题!
此处注意,升级Homebrew会将所有已安装的软件包更新为最新版本。如果您的其他一些编码项目依赖于现已弃用的软件包,这可能不适合您在先前版本的brew
中。我不认为这是一个大问题,只是一个FYI!
如果这个OpenSSL的卸载不适合你,那么other ways就可以了,但如果上述解决方案不起作用,我认为会出现更大的问题。
希望它有所帮助!
来源