【发布时间】: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