在 openshift 上导入 CherryPy 失败
Importing CherryPy fails on openshift
我正在 运行在 openshift 齿轮上安装一个基于 cherrypy 的应用程序。最近,每当我尝试访问该站点时,都会收到“503 服务暂时不可用”错误。检查日志,我看到我在尝试导入 CherryPy 时收到 ImportError。这很奇怪 - CherryPy 在我的 requirements.txt 中被列为依赖项,并且过去可以正常导入。我仔细检查以确保我获得了通往 openshift activate_this.py 的正确路径,它似乎是正确的。我不太确定下一步该去哪里;任何帮助,将不胜感激。谢谢!
导入失败在app.py的第14行:
import os
import files
virtenv = os.path.join(os.environ['OPENSHIFT_PYTHON_DIR'], 'virtenv')
virtualenv = os.path.join(virtenv, 'bin', 'activate_this.py')
conf = os.path.join(files.get_root(), "conf", "server.conf")
try:
execfile(virtualenv, dict(__file__=virtualenv))
print virtualenv
except IOError:
pass
import cherrypy
import wsgi
def mount():
def CORS():
cherrypy.response.headers["Access-Control-Allow-Origin"] = os.environ['OPENSHIFT_APP_DNS']
cherrypy.config.update({"tools.staticdir.root": files.get_root()})
cherrypy.tools.CORS = cherrypy.Tool('before_handler', CORS)
cherrypy.tree.mount(wsgi.application(), "/", conf)
def start():
cherrypy.engine.start()
def end():
cherrypy.engine.exit()
if __name__ == "__main__":
mount()
start()
更新
我最终看到(当使用 git bash CLI 推送到 openshift 存储库时)来自 requirements.txt 的依赖项安装失败,但有一些例外我懒得看成呢。然后它继续尝试在 setup.py 中安装依赖项,并且工作正常。
关于正在使用的端口问题...我不知道。我将我的启动从 tree.mount 和 engine.start 更改为快速启动,当我推送到 openshift 时一切正常。只是为了好玩(因为我需要它来 运行 我的测试),我切换回 cherrypy。tree.mount,推它,它工作得很好。
去算一下。
我使用 Openshift 的 app.py 入口点。以下是我如何在 Openshift 上使用金字塔框架启动我的服务器的几个示例。我使用女服务员作为服务器,但我也使用了 cherrypy wsgi 服务器。把不需要的代码注释掉即可。
app.py
#Openshift entry point
import os
from pyramid.paster import get_app
from pyramid.paster import get_appsettings
if __name__ == '__main__':
here = os.path.dirname(os.path.abspath(__file__))
if 'OPENSHIFT_APP_NAME' in os.environ: #are we on OPENSHIFT?
ip = os.environ['OPENSHIFT_PYTHON_IP']
port = int(os.environ['OPENSHIFT_PYTHON_PORT'])
config = os.path.join(here, 'production.ini')
else:
ip = '0.0.0.0' #localhost
port = 6543
config = os.path.join(here, 'development.ini')
app = get_app(config, 'main') #find 'main' method in __init__.py. That is our wsgi app
settings = get_appsettings(config, 'main') #don't really need this but is an example on how to get settings from the '.ini' files
# Waitress (remember to include the waitress server in "install_requires" in the setup.py)
from waitress import serve
print("Starting Waitress.")
serve(app, host=ip, port=port, threads=50)
# Cherrypy server (remember to include the cherrypy server in "install_requires" in the setup.py)
# from cherrypy import wsgiserver
# print("Starting Cherrypy Server on http://{0}:{1}".format(ip, port))
# server = wsgiserver.CherryPyWSGIServer((ip, port), app, server_name='Server')
# server.start()
#Simple Server
# from wsgiref.simple_server import make_server
# print("Starting Simple Server on http://{0}:{1}".format(ip, port))
# server = make_server(ip, port, app)
# server.serve_forever()
#Running 'production.ini' method manually. I find this method the least compatible with Openshift since you can't
#easily start/stop/restart your app with the 'rhc' commands. Mabye somebody can suggest a better way :)
# #Don't forget to set the Host IP in 'production.ini'. Use 8080 for the port for Openshift
# You will need to use the 'pre_build' action hook(pkill python) so it stops the existing running instance of the server on OS
# You also will have to set up another custom action hook so rhc app-restart, stop works.
# See Openshifts Origin User's Guide ( I have not tried this yet)
#Method #1
# print('Running pserve production.ini')
# os.system("pserve production.ini &")
#Method #2
#import subprocess
#subprocess.Popen(['pserve', 'production.ini &'])
我正在 运行在 openshift 齿轮上安装一个基于 cherrypy 的应用程序。最近,每当我尝试访问该站点时,都会收到“503 服务暂时不可用”错误。检查日志,我看到我在尝试导入 CherryPy 时收到 ImportError。这很奇怪 - CherryPy 在我的 requirements.txt 中被列为依赖项,并且过去可以正常导入。我仔细检查以确保我获得了通往 openshift activate_this.py 的正确路径,它似乎是正确的。我不太确定下一步该去哪里;任何帮助,将不胜感激。谢谢!
导入失败在app.py的第14行:
import os
import files
virtenv = os.path.join(os.environ['OPENSHIFT_PYTHON_DIR'], 'virtenv')
virtualenv = os.path.join(virtenv, 'bin', 'activate_this.py')
conf = os.path.join(files.get_root(), "conf", "server.conf")
try:
execfile(virtualenv, dict(__file__=virtualenv))
print virtualenv
except IOError:
pass
import cherrypy
import wsgi
def mount():
def CORS():
cherrypy.response.headers["Access-Control-Allow-Origin"] = os.environ['OPENSHIFT_APP_DNS']
cherrypy.config.update({"tools.staticdir.root": files.get_root()})
cherrypy.tools.CORS = cherrypy.Tool('before_handler', CORS)
cherrypy.tree.mount(wsgi.application(), "/", conf)
def start():
cherrypy.engine.start()
def end():
cherrypy.engine.exit()
if __name__ == "__main__":
mount()
start()
更新
我最终看到(当使用 git bash CLI 推送到 openshift 存储库时)来自 requirements.txt 的依赖项安装失败,但有一些例外我懒得看成呢。然后它继续尝试在 setup.py 中安装依赖项,并且工作正常。
关于正在使用的端口问题...我不知道。我将我的启动从 tree.mount 和 engine.start 更改为快速启动,当我推送到 openshift 时一切正常。只是为了好玩(因为我需要它来 运行 我的测试),我切换回 cherrypy。tree.mount,推它,它工作得很好。
去算一下。
我使用 Openshift 的 app.py 入口点。以下是我如何在 Openshift 上使用金字塔框架启动我的服务器的几个示例。我使用女服务员作为服务器,但我也使用了 cherrypy wsgi 服务器。把不需要的代码注释掉即可。
app.py
#Openshift entry point
import os
from pyramid.paster import get_app
from pyramid.paster import get_appsettings
if __name__ == '__main__':
here = os.path.dirname(os.path.abspath(__file__))
if 'OPENSHIFT_APP_NAME' in os.environ: #are we on OPENSHIFT?
ip = os.environ['OPENSHIFT_PYTHON_IP']
port = int(os.environ['OPENSHIFT_PYTHON_PORT'])
config = os.path.join(here, 'production.ini')
else:
ip = '0.0.0.0' #localhost
port = 6543
config = os.path.join(here, 'development.ini')
app = get_app(config, 'main') #find 'main' method in __init__.py. That is our wsgi app
settings = get_appsettings(config, 'main') #don't really need this but is an example on how to get settings from the '.ini' files
# Waitress (remember to include the waitress server in "install_requires" in the setup.py)
from waitress import serve
print("Starting Waitress.")
serve(app, host=ip, port=port, threads=50)
# Cherrypy server (remember to include the cherrypy server in "install_requires" in the setup.py)
# from cherrypy import wsgiserver
# print("Starting Cherrypy Server on http://{0}:{1}".format(ip, port))
# server = wsgiserver.CherryPyWSGIServer((ip, port), app, server_name='Server')
# server.start()
#Simple Server
# from wsgiref.simple_server import make_server
# print("Starting Simple Server on http://{0}:{1}".format(ip, port))
# server = make_server(ip, port, app)
# server.serve_forever()
#Running 'production.ini' method manually. I find this method the least compatible with Openshift since you can't
#easily start/stop/restart your app with the 'rhc' commands. Mabye somebody can suggest a better way :)
# #Don't forget to set the Host IP in 'production.ini'. Use 8080 for the port for Openshift
# You will need to use the 'pre_build' action hook(pkill python) so it stops the existing running instance of the server on OS
# You also will have to set up another custom action hook so rhc app-restart, stop works.
# See Openshifts Origin User's Guide ( I have not tried this yet)
#Method #1
# print('Running pserve production.ini')
# os.system("pserve production.ini &")
#Method #2
#import subprocess
#subprocess.Popen(['pserve', 'production.ini &'])