【问题标题】:Stripe no longer supports API requests made with TLS 1.0Stripe 不再支持使用 TLS 1.0 发出的 API 请求
【发布时间】:2017-02-04 13:40:33
【问题描述】:

我正在使用Python Stripe package。我收到错误Stripe no longer supports API requests made with TLS 1.0。我在 Mac 上使用 Python 2.7。我该如何解决这个问题?

# Set this to your Stripe secret key (use your test key!)  
stripe.api_key = "sk_test_VAjLc9DN9BXMS3GPvFn5W92c"   

# Get the credit card details   
token = info['stripeToken']  
amount = info['amount']   
description = info['description']  

# Create the charge on Stripe's servers - this will charge the user's card   
charge = stripe.Charge.create(
    amount=amount,
    currency="usd",
    card=token,
    description=description
)
Traceback (most recent call last):
  File "/Users/vertace/Desktop/payableApp-Sumup/payableAppServer.py", line 23, in pay
    description=description
  File "/Library/Python/2.7/site-packages/stripe/resource.py", line 466, in create
    response, api_key = requestor.request('post', url, params, headers)
  File "/Library/Python/2.7/site-packages/stripe/api_requestor.py", line 140, in request
    resp = self.interpret_response(rbody, rcode, rheaders)
  File "/Library/Python/2.7/site-packages/stripe/api_requestor.py", line 288, in interpret_response
    self.handle_api_error(rbody, rcode, resp, rheaders)
  File "/Library/Python/2.7/site-packages/stripe/api_requestor.py", line 163, in handle_api_error
    rheaders)
AuthenticationError: Request req_A4IYdjtgwILuyV: Stripe no longer supports API requests made with TLS 1.0. Please initiate HTTPS connections with TLS 1.2 or later. You can learn more about this at https://stripe.com/blog/upgrading-tls.

【问题讨论】:

标签: python stripe-payments


【解决方案1】:
pip install pyopenssl

pip uninstall requests

pip install requests

【讨论】:

  • 如果您能提供一些解释来说明为什么这样可以解决问题,将会非常有帮助。
  • 该解决方案对我有用,但正如@Graham 指出的那样,提供一些解释会非常有帮助。我在 Stripe 文档中找不到任何关于与 pyopenssl 不兼容的内容。谢谢!
【解决方案2】:

我遇到了这个问题,以下解决方案解决了这个问题。 (在 Mac OS Sierra 上工作)

  1. 首先检查你是否有从 OS 安装版本运行的 python 或通过 Homebrew 安装的。为此,您可以运行

    which python
    

如果您得到结果 /usr/bin/python 表示您正在从您的操作系统版本运行 Python。如果发生这种情况,请运行(假设您已经安装了自制软件)。

    brew install python

也许,你可能需要

    brew link --overwrite python

这将导致安装新版本的 Python,而这正是您将要使用的版本。

  1. 在新的 brew Python 版本上安装 virtualenv。

    pip install virtualenv
    

需要检查 virtualenv 是否指向 Python OS 安装的版本。这可以检查运行(从您激活的环境)

    nano $(which virtualenv)
  1. 检查第一行是否指向

    #!/usr/bin/env python
    

在您的终端上运行相同的路径并检查 Python 版本是否与您通过 Homebrew (/usr/local/bin/python) 安装的版本相同

  1. 激活您的 virtualenv 环境(源 env/bin/activate),安装您的依赖项(pip install 'your requirements file')并运行您的服务器。

  2. 测试您的 Stripe 流程。现在应该可以成功了。

【讨论】:

    【解决方案3】:

    在 ssl.conf 中使用以下内容设置 apache 配置 SSLProtocol -All +TLSv1.2

    【讨论】:

      【解决方案4】:

      按照完全相同的指令可以解决问题:https://support.stripe.com/questions/how-do-i-upgrade-my-stripe-integration-from-tls-1-0-to-tls-1-2#python

      sudo pip install pyOpenSSL backports.ssl requests
      

      【讨论】:

        【解决方案5】:

        在 Python 2.7 中,我在这些版本的 pyOpenSSL 和请求中遇到了这个问题:

        pyopenssl==17.2.0

        请求==2.6.0

        为了解决这个问题,我将它们都升级到了这些版本:

        pyopenssl==17.3.0

        请求==2.18.4

        要升级它们: pip install pyopenssl --upgrade pip install requests --upgrade

        【讨论】:

          猜你喜欢
          • 2017-01-19
          • 2018-03-28
          • 1970-01-01
          • 1970-01-01
          • 2013-09-05
          • 2020-09-26
          • 2021-05-03
          • 1970-01-01
          • 2019-03-04
          相关资源
          最近更新 更多