在进行Stripe
stripe.Customer.create(email = email)
调用时,我收到此类运行时错误
APIError: 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.
此错误仅在本地开发服务器上显示,但不在生产中显示。我当然升级了我的条带库:
pip install -t lib --upgrade stripe==1.19.1
为了消除这可能是pip upgrade
的问题,我还尝试删除旧的lib / stripe目录及其依赖项,然后进行全新安装。但这并没有什么不同。
答案 0 :(得分:3)
您的appengine_config.py
是否已包含此内容?
import os
from google.appengine.ext import vendor
from google.appengine.ext.appstats import recording
appstats_CALC_RPC_COSTS = True
# Add any libraries installed in the "lib" folder.
vendor.add('lib')
def webapp_add_wsgi_middleware(app):
app = recording.appstats_wsgi_middleware(app)
return app
# if on localhost
if os.environ.get('SERVER_SOFTWARE', '').startswith('Development'):
import imp
import os.path
import inspect
from google.appengine.tools.devappserver2.python import sandbox
sandbox._WHITE_LIST_C_MODULES += ['_ssl', '_socket']
# Use the system socket.
real_os_src_path = os.path.realpath(inspect.getsourcefile(os))
psocket = os.path.join(os.path.dirname(real_os_src_path), 'socket.py')
imp.load_source('socket', psocket)
else:
# Doing this on dev_appserver/localhost seems to cause outbound https requests to fail
from lib import requests
from lib.requests_toolbelt.adapters import appengine as requests_toolbelt_appengine
# Use the App Engine Requests adapter. This makes sure that Requests uses
# URLFetch.
requests_toolbelt_appengine.monkeypatch()
我复制了我的整个文件,因为我不确定你已经拥有哪些部分,但关键部分是最后的if-else。我在使用TLS 1.2处理prod时遇到了一大堆麻烦,主要归结为为App Engine的特殊ssl库指定版本2.7.11
& requests_toolbelt_appengine.monkeypatch()
。
就像你这样,我在localhost上破坏了ssl,所以现在我只在prod上做requests_toolbelt_appengine.monkeypatch()
,而在localhost上我这样做是白色列出本机套接字库'你可能已经看过了。部分结果归结为您正在使用的各种版本的组合。希望这会有所帮助。
我app.yaml
的重要项目:
env_variables:
theme: 'default'
GAE_USE_SOCKETS_HTTPLIB : 'true' # TLS 1.2
libraries:
- name: jinja2
version: "2.6"
- name: webapp2
version: "2.5.2"
- name: markupsafe
version: "0.15"
- name: ssl
version: "2.7.11" # TLS 1.2
- name: pycrypto
version: "2.6"
- name: lxml
version: latest
我也在使用python-requests 2.18.2
编辑:
在我的~/.bash_profile
中,google cloud sdk已添加到我的路径中:
export PATH="/Users/alex/google-cloud-sdk/platform/google_appengine/:$PATH"
。
如果我转到该文件夹,我可以一直跟踪from google.appengine.tools.devappserver2.python import sandbox
的导入。 (下面的截图)