尝试从 Google App Engine 应用调用 braintree.ClientToken.generate() 时遇到此问题,在 dev_appserver.py 上运行 Flask。 dev_appserver.py 当前无法建立传出 SSL 连接。进行上述 braintree 调用产量
ConnectionError: ('Connection aborted.', error(13, 'Permission denied'))
调用在真实的 GAE 环境中进行。它在我的一个 View 中使用过,所以当它失败时,它会破坏我的整个网站流程并显示上述 500 错误。我该如何解决这个问题,以便我可以在本地环境中继续开发?
请您参考如下方法:
我在布伦特里工作。如果有更多问题,可以随时contact our support team
有关 GAE 上 Braintree Python 库的帮助,请参阅 this example on my GitHub .要回答你的问题,你可以force the dev server to use the real Python socket library ,所以 SSL 连接有效:
try:
# This is needed to make local development work with SSL.
# This must be done *before* you import the Braintree Python library.
# See http://stackoverflow.com/a/24066819/500584
# and https://code.google.com/p/googleappengine/issues/detail?id=9246 for more information.
from google.appengine.tools.devappserver2.python import sandbox
sandbox._WHITE_LIST_C_MODULES += ['_ssl', '_socket']
import sys
# this is socket.py copied from a standard python install
import stdlib_socket
sys.modules['socket'] = stdlib_socket
except ImportError as e:
print(e)
