【问题标题】:AttributeError: 'NoneType' object has no attribute 'wrap_socket' in GAE using BraintreeAttributeError:“NoneType”对象在使用 Braintree 的 GAE 中没有属性“wrap_socket”
【发布时间】:2014-09-26 03:11:52
【问题描述】:

我正在 Google App Engine 中测试一个嵌入 Braintree 平台的应用。我正在使用他们的代码进行这个测试来处理一个虚构的交易。在我的 html 中,我有一个表单,提交时会将其信息路由到下面的“/create_transaction”。服务器代码是:

@app.route("/create_transaction", methods=["POST"])
def create_transaction():
    result = braintree.Transaction.sale({
        "amount": "1000.00",
        "credit_card": {
            "number": request.form["number"],
            "cvv": request.form["cvv"],
            "expiration_month": request.form["month"],
            "expiration_year": request.form["year"]
        },
        "options": {
            "submit_for_settlement": True
        }
    })
    if result.is_success:
        return "<h1>Success! Transaction ID: {0}</h1>".format(result.transaction.id)
    else:
        return "<h1>Error: {0}</h1>".format(result.message) 

浏览器没有返回结果,而是呈现内部服务器错误 500。Traceback 如下:

ERROR    2014-09-26 03:08:13,852 app.py:1423] Exception on /create_transaction [POST]
Traceback (most recent call last):
  File "/home/manuel/Google/braintree_app/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/manuel/Google/braintree_app/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/manuel/Google/braintree_app/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/manuel/Google/braintree_app/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/manuel/Google/braintree_app/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/manuel/Google/braintree_app/app.py", line 40, in create_transaction
    "submit_for_settlement": True
  File "/home/manuel/Google/braintree_app/braintree/transaction.py", line 302, in sale
    return Transaction.create(params)
  File "/home/manuel/Google/braintree_app/braintree/transaction.py", line 397, in create
    return Configuration.gateway().transaction.create(params)
  File "/home/manuel/Google/braintree_app/braintree/transaction_gateway.py", line 33, in create
    return self._post("/transactions", {"transaction": params})
  File "/home/manuel/Google/braintree_app/braintree/transaction_gateway.py", line 137, in _post
    response = self.config.http().post(url, params)
  File "/home/manuel/Google/braintree_app/braintree/util/http.py", line 49, in post
    return self.__http_do("POST", path, params)
  File "/home/manuel/Google/braintree_app/braintree/util/http.py", line 71, in __http_do
    raise e
AttributeError: 'NoneType' object has no attribute 'wrap_socket'

为什么 GAE 会抛出这个异常?

【问题讨论】:

  • 它位于 Braintree 代码中,所以我会说它与它有关,而不是与 GAE 相关。它是否经过测试可以与 GAE 一起使用?它是否试图做一些 GAE 沙盒模型中不允许的事情?
  • 我在我的计算机上本地测试了相同的脚本并且它有效。我不认为它试图做一些不允许的事情,因为它只是试图通过发送信用卡信息来发布交易,在我的情况下这是一个假的。所以它实际上只是通过套接字发送的数字。
  • 您的代码使用了@app 装饰器。问题由此而来。

标签: python google-app-engine braintree


【解决方案1】:

我在布伦特里工作。如果您需要更多帮助,可以随时get in touch with our support team

这似乎是problem with certain versions of urllib3 / requests (a Braintree dependency) on GAE

尝试将此添加到您的 app.yaml 文件中:

libraries:
- name: ssl
  version: latest

并确保您为应用程序启用了计费功能。

如果这不能解决问题,您可以查看上面链接的 github 问题以获取更多信息。

【讨论】:

  • 感谢您抽出宝贵时间查看此内容。如上面链接中的问题所述,我添加了库并启用了计费。但是,我有以下错误:文件“/home/manuel/Google/braintree_app/braintree/util/http.py”,第 71 行,在 __http_do raise e ConnectionError: ('Connection aborted.', error(13, 'Permission拒绝')) 这看起来我无法访问图书馆,因为 GAE 中禁用了计费,但我可以确认计费已启用。我被卡住了。
  • @ManuelGodoy 我认为我们已经回复了您的支持票,但对于其他阅读者 - 正如我在答案中链接的问题中所述,您可能需要启用计费才能使用来自的套接字库GAE 上的 Python。
  • 正如我在评论中所说,计费已启用,问题仍然存在。
  • @ManuelGodoy 您能检查一下您的应用程序中的requests.__version__ 是什么吗?如果您能找到解决方案,请告诉我们,但如果没有,我可以在星期五花一些时间亲自尝试,我想确保尽可能地复制您的设置。
  • 版本 = '2.4.1'
猜你喜欢
  • 2015-04-19
  • 1970-01-01
  • 2019-01-01
  • 2021-12-26
  • 2019-07-23
  • 2018-05-13
  • 2020-09-07
  • 2017-05-03
  • 2023-03-16
相关资源
最近更新 更多