0

我正在尝试从 Openshift 2 迁移到 3,但我被困了几行。

在从Openshift Pyramidstarter 模板复制的带有 Waitress 服务器的 Python3 Pyramid 中运行。问题出在os.environ.

from waitress import serve
print('Binding to '+os.environ['HOME_SERVICE_HOST']) #fomerly OPENSHIFT_PYTHON_IP
print("Starting Waitress.")
serve(app, host=os.environ['HOME_SERVICE_HOST'], port=8080, threads=50)

这给了我以下错误

Binding to 172.30.224.51
Starting Waitress.
Traceback (most recent call last):
  File "app.py", line 34, in <module>
    serve(app, host=ip, port=port, threads=50)
  File "/opt/app-root/lib/python3.5/site-packages/waitress-1.0.2-py3.5.egg/waitress/__init__.py", line 11, in serve
    server = _server(app, **kw)
  File "/opt/app-root/lib/python3.5/site-packages/waitress-1.0.2-py3.5.egg/waitress/server.py", line 85, in create_server
    sockinfo=sockinfo)
  File "/opt/app-root/lib/python3.5/site-packages/waitress-1.0.2-py3.5.egg/waitress/server.py", line 182, in __init__
    self.bind_server_socket()
  File "/opt/app-root/lib/python3.5/site-packages/waitress-1.0.2-py3.5.egg/waitress/server.py", line 294, in bind_server_socket
    self.bind(sockaddr)
  File "/opt/rh/rh-python35/root/usr/lib64/python3.5/asyncore.py", line 329, in bind
    return self.socket.bind(addr)
OSError: [Errno 99] Cannot assign requested address

我已经尝试了其他一些选项。os.environ键如下:['KUBERNETES_PORT_53_UDP_PORT', 'PIP_NO_CACHE_DIR', 'KUBERNETES_PORT_53_TCP_PORT', 'STI_SCRIPTS_PATH', 'PYTHONIOENCODING', 'X_SCLS', 'KUBERNETES_PORT_443_TCP_PROTO', 'HOME_SERVICE_PORT', 'HOME_SERVICE_HOST', 'KUBERNETES_PORT_53_TCP_ADDR', 'LANG', 'MANPATH', 'KUBERNETES_PORT_53_UDP', 'KUBERNETES_PORT_443_TCP', 'HOME_SERVICE_PORT_8080_TCP', 'PWD', 'KUBERNETES_PORT', 'KUBERNETES_SERVICE_PORT_HTTPS', 'VIRTUAL_ENV', 'PYTHON_VERSION', 'KUBERNETES_PORT_443_TCP_ADDR', 'HOME_PORT_8080_TCP_PORT', 'HOME_PORT', 'HOME_PORT_8080_TCP_ADDR', 'HOME_PORT_8080_TCP_PROTO', 'OPENSHIFT_BUILD_SOURCE', 'KUBERNETES_PORT_53_TCP_PROTO', 'KUBERNETES_PORT_53_UDP_PROTO', 'LD_PRELOAD', 'DESCRIPTION', 'LIBRARY_PATH', 'OPENSHIFT_BUILD_NAMESPACE', 'KUBERNETES_PORT_53_TCP', 'container', 'PATH', 'KUBERNETES_SERVICE_HOST', 'KUBERNETES_SERVICE_PORT_DNS_TCP', 'KUBERNETES_PORT_53_UDP_ADDR', 'KUBERNETES_SERVICE_PORT', 'PYTHONUNBUFFERED', 'KUBERNETES_PORT_443_TCP_PORT', 'OPENSHIFT_BUILD_COMMIT', 'NSS_WRAPPER_PASSWD', 'HOME_PORT_8080_TCP', 'KUBERNETES_SERVICE_PORT_DNS', 'SUMMARY', 'STI_SCRIPTS_URL', 'NSS_WRAPPER_GROUP', 'PKG_CONFIG_PATH', 'SHLVL', 'OPENSHIFT_BUILD_REFERENCE', 'HOME', 'HOSTNAME', 'LD_LIBRARY_PATH', 'LC_ALL', 'XDG_DATA_DIRS', 'OPENSHIFT_BUILD_NAME']

例外:我拼命尝试绑定到 localhost (127.0.0.1),但我的权限被拒绝。

4

1 回答 1

1

直接绑定到 0.0.0.0 就好了。

例如:

serve(app, host='0.0.0.0', port=8080, threads=50)
于 2017-09-02T19:19:13.123 回答