I am testing an app in the Google App Engine that embeds the Braintree platform. I am using their code for this test to process a fictitious transaction. In my html I have a form that when submitted it routes its information to "/create_transaction" below. The server code is:
@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)
Instead of returning the result, the browser renders an Internal Server Error 500. The Traceback is the following:
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'
Why is GAE throwing this exception?
I work at Braintree. If you need more help, you can always get in touch with our support team.
This appears to be a problem with certain versions of urllib3 / requests (a Braintree dependency) on GAE.
Try adding this to your app.yaml
file:
libraries:
- name: ssl
version: latest
And make sure you have billing enabled for the application.
If that doesn't solve it, you can see the github issue linked above for more info.