IP binding in Openshift 3 Python

227 views Asked by At

I am trying to migrate from Openshift 2 to 3 and I am stuck a few lines in.

In a running a Python3 Pyramid with Waitress server as copied from a Openshift Pyramidstarter template. The problem arises from different keys in 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)

This gives me the following error

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

I have tried a few other of the options. The os.environ keys are the following: ['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'].

Exception: I desperately tried binding to localhost (127.0.0.1) and I got permission denied.

1

There are 1 answers

2
Will Gordon On BEST ANSWER

Just bind it directly to 0.0.0.0.

For example:

serve(app, host='0.0.0.0', port=8080, threads=50)