尝试从 Google App Engine 应用调用 braintree.ClientToken.generate()
(在 dev_appserver.py
上运行 Flask)时遇到此问题。 dev_appserver.py
当前无法建立传出 SSL 连接。进行上述 Braintree 调用会产生
ConnectionError: ('连接已中止。', error(13, '权限被拒绝'))
该通话在真实的 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)
关于python - dev_appserver.py 无法发出 SSL 请求的解决方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32318905/