AttributeError:'NoneType'对象在使用Braintree的GAE中没有属性'wrap_socket'

时间:2014-09-26 03:11:52

标签: python google-app-engine braintree

我正在测试嵌入Braintree平台的Google App Engine中的应用。我正在使用他们的代码进行此测试来处理虚构的事务。在我的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会抛出此异常?

1 个答案:

答案 0 :(得分:1)

我在Braintree工作。如果您需要更多帮助,可以随时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问题以获取更多信息。