使用Python API库在Google AppEngine上进行Stripe支付

5 投票
1 回答
1353 浏览
提问于 2025-04-18 06:06

我刚刚把Stripe的API库更新到了最新版本,但在Google AppEngine上它不再工作了,因为GAE阻止了一些包的导入,比如sockets和SSL。

ERROR    2014-05-10 09:55:16,576 base.py:215] Internal Server Error: /api/billing/subscribe_to_paid_plan/stripe
    Traceback (most recent call last):
...
     File "/src/classes/billing/api_views.py", line 3, in <module>
        import stripe
      File "/src/stripe/__init__.py", line 16, in <module>
        from stripe.resource import (  # noqa
      File "/src/stripe/resource.py", line 5, in <module>
        from stripe import api_requestor, error, util
      File "/src/stripe/api_requestor.py", line 5, in <module>
        import ssl
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 60, in <module>
        import _ssl             # if we can't import it, let the error propagate
      File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py", line 852, in load_module
        raise ImportError('No module named %s' % fullname)
    ImportError: No module named _ssl

有没有可能让它在Google AppEngine上正常工作呢?

1 个回答

7

你需要通过在你的 app.yaml 文件中添加以下内容来启用 SSL:

libraries:
- name: ssl
  version: latest

编辑:下面提到的错误还没有修复,但我为 Stripe 的 Python 绑定贡献了一个补丁来解决这个问题。

目前在应用引擎的开发服务器中有一个错误(我计划去修复它),可以通过以下方法绕过:

/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py 文件中的字典 _WHITE_LIST_C_MODULES 中添加 "_ssl" 和 "_socket" 这两个键。

将 Google 提供的 /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/dis27 中的 socket.py 文件替换为你 Python 框架中的 socket.py 文件。

撰写回答