我有一个用 python 编写的 openshift 应用程序,并且想使用 Flask-mysql
import os
from datetime import datetime
from flask import Flask, request, flash, url_for, redirect, \
render_template, abort, send_from_directory, json
from flask.ext.mysql import MySQL
app = Flask(__name__)
app.config.from_pyfile('flaskapp.cfg')
mysql = MySQL()
# MySQL configurations
app.config['MYSQL_DATABASE_USER'] = ' adminuWfyNxG'
app.config['MYSQL_DATABASE_PASSWORD'] = ' '
app.config['MYSQL_DATABASE_DB'] = ''
app.config['MYSQL_DATABASE_HOST'] = '127.4.253.2:3306'
mysql.init_app(app)
#conn = mysql.connect()
#cursor = conn.cursor()
@app.route("/")
def index():
return render_template('index.html')
@app.route('/showSignUp')
def showSignUp():
return render_template('signup.html')
@app.route('/<path:resource>')
def serveStaticResource(resource):
return send_from_directory('static/', resource)
@app.route('/signUp',methods=['POST','GET'])
def signUp():
try:
_name = request.form['inputName']
_email = request.form['inputEmail']
_password = request.form['inputPassword']
# validate the received values
if _name and _email and _password:
# All Good, let's call MySQL
conn = mysql.connect()
cursor = conn.cursor()
cursor.callproc('sp_createUser',(_name,_email,_password))
data = cursor.fetchall()
if len(data) is 0:
conn.commit()
return json.dumps({'message':'User created successfully !'})
else:
return json.dumps({'error':str(data[0])})
else:
return json.dumps({'html':'<span>Enter the required fields</span>'})
except Exception as e:
return json.dumps({'error':str(e)})
finally:
cursor.close()
conn.close()
if __name__ == "__main__":
app.run()
当我尝试在我的应用程序上运行它时,我收到一个错误。
HTTP/1.1 503 服务暂时不可用 日期:2015 年 9 月 2 日星期三 19:09:34 GMT 内容长度:428 连接:关闭 内容类型:text/html;字符集=iso-8859-1
我根据 openshift 配置使用数据库用户、密码、数据库名称和主机。
任何人都可以帮助我吗?
日志文件输出:
在 127.4.253.1:8080 上启动 WSGIServer 类型烧瓶 ... * 在http://127.4.253.1:8080/ 127.4.253.1 上运行 - - [03/Sep/2015 13:40:33] "GET /showSignUp HTTP/1.1 “ 500 - 请求错误:回溯(最近一次调用最后一次):文件“/opt/rh/python27/root/usr/lib/python2.7/site-packages/werkzeug/serving.p y”,第 159 行,在 run_wsgi执行(app)文件“/opt/rh/python27/root/usr/lib/python2.7/site-packages/werkzeug/serving.py”,第146行,在执行application_iter = app(environ,start_response)文件“/ var/lib/openshift/55d41b2c0c1e66a0060000b8/app-root/runtime/dependencie s/python/virtenv/lib/python2.7/site-packages/Flask-0.10.1-py2.7.egg/flask/app.py”,第 1836 行,通话中 返回 self.wsgi_app(environ, start_response) 文件“/var/lib/openshift/55d41b2c0c1e66a0060000b8/app-root/runtime/dependencie s/python/virtenv/lib/python2.7/site-packages/Flask-0.10.1-py2 .7.egg/flask/app.py”,第 1836 行,通话中 返回 self.wsgi_app(environ, start_response) 文件“/var/lib/openshift/55d41b2c0c1e66a0060000b8/app-root/runtime/dependencie s/python/virtenv/lib/python2.7/site-packages/Flask-0.10.1-py2 .7.egg/flask/app.py”,第 1820 行,在 wsgi_app 响应 = self.make_response(self.handle_exception(e)) 文件“/var/lib/openshift/55d41b2c0c1e66a0060000b8/app-root/runtime/dependencie s/ python/virtenv/lib/python2.7/site-packages/Flask-0.10.1-py2.7.egg/flask/app.py”,第 1403 行,在 handle_exception reraise(exc_type, exc_value, tb) 文件中“/var /lib/openshift/55d41b2c0c1e66a0060000b8/app-root/runtime/dependencie s/python/virtenv/lib/python2.7/site-packages/Flask-0.10.1-py2.7.egg/flask/app.py“,行1817,在 wsgi_app 响应 = self.full_dispatch_request() 文件"/var/lib/openshift/55d41b2c0c1e66a0060000b8/app-root/runtime/dependencie s/python/virtenv/lib/python2.7/site-packages/Flask-0.10.1-py2.7.egg/flask/app.py" ,第 1477 行,在 full_dispatch_request rv = self.handle_user_exception(e) 文件“/var/lib/openshift/55d41b2c0c1e66a0060000b8/app-root/runtime/dependencie s/python/virtenv/lib/python2.7/site-packages/Flask- 0.10.1-py2.7.egg/flask/app.py”,第 1381 行,在 handle_user_exception reraise(exc_type, exc_value, tb) 文件“/var/lib/openshift/55d41b2c0c1e66a0060000b8/app-root/runtime/dependencie s/ python/virtenv/lib/python2.7/site-packages/Flask-0.10.1-py2.7.egg/flask/app.py”,第 1473 行,在 full_dispatch_request rv = self.preprocess_request() 文件中“/var/ lib/openshift/55d41b2c0c1e66a0060000b8/app-root/runtime/dependencie s/python/virtenv/lib/python2。7/site-packages/Flask-0.10.1-py2.7.egg/flask/app.py”,第 1666 行,在 preprocess_request rv = func() 文件中“/var/lib/openshift/55d41b2c0c1e66a0060000b8/app-root/ runtime/dependencie s/python/virtenv/lib/python2.7/site-packages/Flask_MySQL-1.3-py2.7.egg/flaskext/mysql.py”,第 48 行,在 before_request ctx.mysql_db = self.connect()文件“/var/lib/openshift/55d41b2c0c1e66a0060000b8/app-root/runtime/dependencie s/python/virtenv/lib/python2.7/site-packages/Flask_MySQL-1.3-py2.7.egg/flaskext/mysql.py” ,第 44 行,在连接中返回 MySQLdb.connect(**self.connect_args) 文件“/opt/rh/python27/root/usr/lib64/python2.7/site-packages/MySQLdb//var/lib/openshift/55d41b2c0c1e66a0060000b8/app-root/runtime/dependencie s/python/virtenv/lib/python2.7/site-packages/Flask_MySQL-1.3-py2.7.egg/flaskext/mysql.py”,行48、在before_request ctx.mysql_db = self.connect() 文件"/var/lib/openshift/55d41b2c0c1e66a0060000b8/app-root/runtime/dependencie s/python/virtenv/lib/python2.7/site-packages/Flask_MySQL-1.3 -py2.7.egg/flaskext/mysql.py”,第 44 行,在连接中返回 MySQLdb.connect(**self.connect_args) 文件“/opt/rh/python27/root/usr/lib64/python2.7/site -packages/MySQLdb//var/lib/openshift/55d41b2c0c1e66a0060000b8/app-root/runtime/dependencie s/python/virtenv/lib/python2.7/site-packages/Flask_MySQL-1.3-py2.7.egg/flaskext/mysql.py”,行48、在before_request ctx.mysql_db = self.connect() 文件"/var/lib/openshift/55d41b2c0c1e66a0060000b8/app-root/runtime/dependencie s/python/virtenv/lib/python2.7/site-packages/Flask_MySQL-1.3 -py2.7.egg/flaskext/mysql.py”,第 44 行,在连接中返回 MySQLdb.connect(**self.connect_args) 文件“/opt/rh/python27/root/usr/lib64/python2.7/site -packages/MySQLdb/7/site-packages/Flask_MySQL-1.3-py2.7.egg/flaskext/mysql.py”,第44行,在connect返回MySQLdb.connect(**self.connect_args)文件“/opt/rh/python27/root/ usr/lib64/python2.7/site-packages/MySQLdb/7/site-packages/Flask_MySQL-1.3-py2.7.egg/flaskext/mysql.py”,第44行,在connect返回MySQLdb.connect(**self.connect_args)文件“/opt/rh/python27/root/ usr/lib64/python2.7/site-packages/MySQLdb/init .py”,第 81 行,在 Connect 返回 Connection(*args, **kwargs) 文件“/opt/rh/python27/root/usr/lib64/python2.7/site-packages/MySQLdb/connections.py” ,第 187 行,在init super(Connection, self) .init (*args, **kwargs2) OperationalError: (2005, "Unknown MySQL server host '127.4.253.2:3306' (1)")