我有一个Android客户端和一个应该相互通信的服务器。我正在使用烧瓶并在app引擎上托管我的服务器。这是main.py
文件:
from flask import Flask
import braintree
braintree.Configuration.configure(braintree.Environment.Sandbox,
merchant_id="something_censored",
public_key="something_censored",
private_key="something_censored")
app = Flask(__name__)
if __name__ == '__main__':
app.run()
@app.route('/')
def hello_world():
return 'Hello World!'
@app.route('/<name>')
def hello_name(name):
return "Howdy {}".format(name)
@app.route('/client_token', methods=["GET"])
def client_token():
return braintree.ClientToken.generate()
@app.route('/create_customer/<firstName>/<lastName>/<email>', methods=["GET"])
def create_customer(firstName, lastName, email):
result = braintree.Customer.create({
"first_name": firstName,
"last_name": lastName,
"email": email,
})
return result.customer.id
@app.route('/create_payment_method_for_customer/<customerId>/<clientNonce>', methods=["POST"])
def create_payment_method_for_customer(customerId, clientNonce):
braintree.PaymentMethod.create({
"customer_id": customerId,
"payment_method_nonce": clientNonce,
"options": {
"verify_card": True,
"verification_merchant_account_id": "ydt4s72wzw46wdbs",
"verification_amount": "0.00",
}
})
@app.route('/get_customer_payment_methods/<customer_id>')
def get_customer_payment_methods(customer_id):
result = braintree.Customer.find(customer_id)
return result.payment_methods
我已经使用pip install braintree
命令在python中下载了braintree服务器sdk,我已经安装了2.7 python应用程序引擎sdk。
在http://birthpayserver.appspot.com/部署了在app引擎上托管的烧瓶服务器后,我调用了'/ client_token'路由,如下所示:
Uri.Builder builder = new Uri.Builder()
.scheme("http")
.authority("www.birthpayserver.appspot.com")
.appendPath("create_customer")
.appendPath(firstName)
.appendPath(lastName)
.appendPath(email);
String url = builder.build().toString();
AsyncHttpClient client = new AsyncHttpClient();
client.get(url, new TextHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, String customerId) {
mCustomerId = customerId;
}
@Override
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
Toast.makeText(getBaseContext(), "Failed to create account, try again.", Toast.LENGTH_LONG).show();
Log.d(LOG_TAG, responseString);
}
});
调用onFailure
方法,responseString
等于:{/ p>
<html><head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>500 Server Error</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: Server Error</h1>
<h2>The server encountered an error and could not complete your request.
<p>Please try again in 30 seconds.</h2>
<h2></h2>
</body></html>
当我运行我的服务器时,日志如下:
INFO 2016-08-07 13:07:23,435 sdk_update_checker.py:229] Checking for updates to the SDK.
INFO 2016-08-07 13:07:24,348 sdk_update_checker.py:257] The SDK is up to date.
WARNING 2016-08-07 13:07:24,547 simple_search_stub.py:1146] Could not read search indexes from /var/folders/vv/4vyp0dmd5fl0v7n7pgmj0kyc0000gn/T/appengine.birthpayserver.tomfinet/search_indexes
INFO 2016-08-07 13:07:24,551 api_server.py:205] Starting API server at: http://localhost:54454
INFO 2016-08-07 13:07:24,556 api_server.py:648] Applying all pending transactions and saving the datastore
INFO 2016-08-07 13:07:24,556 api_server.py:651] Saving search indexes
Traceback (most recent call last):
File "/usr/local/google_appengine/dev_appserver.py", line 89, in <module>
_run_file(__file__, globals())
File "/usr/local/google_appengine/dev_appserver.py", line 85, in _run_file
execfile(_PATHS.script_file(script_name), globals_)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 1040, in <module>
main()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 1033, in main
dev_server.start(options)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 824, in start
self._dispatcher.start(options.api_host, apis.port, request_data)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/dispatcher.py", line 194, in start
_module.start()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/module.py", line 1177, in start
self._balanced_module.start()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/wsgi_server.py", line 315, in start
self._start_all_fixed_port(host_ports)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/wsgi_server.py", line 352, in _start_all_fixed_port
raise BindError('Unable to bind %s:%s' % self.bind_addr)
google.appengine.tools.devappserver2.wsgi_server.BindError: Unable to bind 127.0.0.1:8080
Process finished with exit code 1
编辑:
再次运行我的烧瓶服务器时,日志显示有ImportError: No module named braintree
,但我安装了braintree。
如何让服务器在app引擎上运行,以便它接受并响应http
个请求?