我最近的openhift装备有问题,我得到python错误错误13,权限被拒绝。我在这里查了一下,发现大多数遇到同样问题的人都忘了if __name__ == "__main__":
之前的app.run()
声明,但我仍然有同样的问题。根据登录openshift的日志,错误似乎是从内置于python的socket.py中产生的。
这是我在openshift上的第二个装备,这个和我的第一个装备是用烧瓶制造的。第一个工作正常,但我的第二个工作不会......
这是我在openshift的python日志中收到的错误消息:
* Running on http://127.0.0.1:5000/
Traceback (most recent call last):
File "app.py", line 24, in <module>
app.run()
File "/var/lib/openshift/54d242655973ca23980001d1/python/virtenv /lib/python2.7/site-packages/flask/app.py", line 772, in run
run_simple(host, port, self, **options)
File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/werkzeug/serving.py", line 617, in run_simple
inner()
File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/werkzeug/serving.py", line 599, in inner
passthrough_errors, ssl_context).serve_forever()
File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/werkzeug/serving.py", line 408, in make_server
passthrough_errors, ssl_context)
File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/werkzeug/serving.py", line 334, in __init__
HTTPServer.__init__(self, (host, int(port)), handler)
File "/opt/rh/python27/root/usr/lib64/python2.7/SocketServer.py", line 419, in __init__
self.server_bind()
File "/opt/rh/python27/root/usr/lib64/python2.7/BaseHTTPServer.py", line 108, in server_bind
SocketServer.TCPServer.server_bind(self)
File "/opt/rh/python27/root/usr/lib64/python2.7/SocketServer.py", line 430, in server_bind
self.socket.bind(self.server_address)
File "/opt/rh/python27/root/usr/lib64/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 13] Permission denied
编辑2: 所以我将ip更改为OPENSHIFT_PYTHON_IP,但错误日志看起来完全一样。这是我的wsgi.py代码
#!/usr/bin/python
import os
virtenv = os.environ['OPENSHIFT_PYTHON_DIR'] + '/virtenv/'
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
try:
execfile(virtualenv, dict(__file__=virtualenv))
except IOError:
pass
def run_gevent_server(app, ip, port=8080):
from gevent.pywsgi import WSGIServer
WSGIServer((ip, port), app).serve_forever()
def run_simple_httpd_server(app, ip, port=8080):
from wsgiref.simple_server import make_server
make_server(ip, port, app).serve_forever()
from server import app as application
#
# Below for testing only
#
if __name__ == '__main__':
ip = os.environ['OPENSHIFT_PYTHON_IP']
port = 8080
zapp = impo.load_source('application', 'wsgi/application')
try:
run_gevent_server(application, ip, port)
except:
run_simple_httpd_server(zapp.application, ip, port)
答案 0 :(得分:0)
您使用的是哪个端口/ IP地址?你必须绑定到你的openshift ip地址的端口8080,你不能绑定到127.0.0.1,这是不允许的。