即使在升级到最新版本后,Google App Engine上的条纹调用仍然出现错误 [英] Error with Stripe calls on Google App Engine even after upgrading to latest
问题描述
在制作 Stripe
调用(例如 stripe.Customer.create(email = email)
APIError:Stripe不再支持使用TLS 1.0创建的API请求。
请使用TLS 1.2或更高版本启动HTTPS连接。
您可以通过https://stripe.com/blog/upgrading-tls了解更多信息。
仅在本地开发服务器上显示此错误,但不在生产上显示。我当然升级了我的条纹库,如下所示:
pip install -t lib --upgrade stripe == 1.19.1
消除这种可能性是 pip upgrade $ c的问题$ c>,我也尝试删除旧的lib / stripe目录和它的依赖关系,然后进行全新安装。但这并没有什么不同。
appengine_config.py
有这个吗? import os
from google.appengine.ext import vendor
from google.appengine.ext.appstats导入记录
appstats_CALC_RPC_COSTS = True
#添加安装在lib文件夹中的任何库。
vendor.add('lib')
def webapp_add_wsgi_middleware(app):
app = recording.appstats_wsgi_middleware(app)
return app
$ b $#如果在本地主机上
如果os.environ.get('SERVER_SOFTWARE','').startswith('Development'):
import imp
import os.path
导入检查google.appengine.tools.devappserver2.python中的
导入沙箱
sandbox._WHITE_LIST_C_MODULES + = ['_ssl','_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:
#在dev_appserver / localhost上执行此操作似乎会导致出站https请求失败
从lib导入请求
from lib.requests_toolbelt.adapters import appengine as requests_toolbelt_appengine
#使用App Engine Requests适配器。这可以确保请求使用
#URLFetch。
requests_toolbelt_appengine.monkeypatch()
我复制了整个文件,因为我不确定哪个你已经拥有的部分,但关键部分是最终的if-else。我经历了一系列的麻烦,让TLS 1.2在prod上工作,主要是为App Engine的特殊ssl库&指定版本 2.7.11
。 requests_toolbelt_appengine.monkeypatch()
。
像你这样在我的本地主机上打破了ssl,所以现在我只在命令上执行 requests_toolbelt_appengine.monkeypatch()
,并且在本地主机上,我做了'白名单本地套接字库'技巧你可能已经看到。部分原因是你使用的是什么样的组合版本。希望这有助于。
我的 app.yaml
中的重要商品:
<$
主题:'default'
GAE_USE_SOCKETS_HTTPLIB:'true'#TLS 1.2
库:
- 名称: jinja2
版本:2.6
- 名称:webapp2
版本:2.5.2
- 名称:markupsafe
版本:0.15
- 名称:ssl
版本:2.7.11#TLS 1.2
- 名称:pycrypto
版本:2.6
- 名称:lxml
版本:latest
另外我正在使用python-requests 2.18.2
编辑:
在我的〜/ .bash_profile
中,google cloud sdk被添加到我的路径中:
export PATH =/ Users / alex / google-cloud-sdk / platform / google_appengine /:$ PATH
。
如果我转到该文件夹,可以从google.appengine.tools.devappserver2.python中导入 import sandbox
一路通过。 (截图如下)
I receive runtime errors like this when making Stripe
calls such as 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.
This error shows up only on the local development server, but not on production. I have of course upgraded my stripe library like this:
pip install -t lib --upgrade stripe==1.19.1
To eliminate the possibility of this being an issue with pip upgrade
, I have also tried removing the old lib/stripe directory and it's dependencies, followed by a fresh install. But that does not make a difference.
Does your appengine_config.py
have this in it yet?
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()
I copied my whole file because I'm not sure which parts you already have, but the key part is that final if-else. I went through a whole mess of trouble getting TLS 1.2 working on prod, which primarily came down to specifying version 2.7.11
for App Engine's special ssl library & requests_toolbelt_appengine.monkeypatch()
.
Like you this broke ssl on localhost for me, so now I only do requests_toolbelt_appengine.monkeypatch()
on prod, and on localhost I do that 'white-listing the native sockets library' trick you've probably seen. Part of this comes down what combination of versions of things you're using. Hopefully this helps.
Notable items from my 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
Also I'm using python-requests 2.18.2
EDIT:
In my ~/.bash_profile
, google cloud sdk was added to my path:
export PATH="/Users/alex/google-cloud-sdk/platform/google_appengine/:$PATH"
.
If I go to that folder, I can follow the imports for from google.appengine.tools.devappserver2.python import sandbox
all the way through. (screenshot included below)
这篇关于即使在升级到最新版本后,Google App Engine上的条纹调用仍然出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!