简体   繁体   English

OSError: [Errno 98] 地址已在 heroku 中使用

[英]OSError: [Errno 98] Address already in use in heroku

So I am trying to create some kind of python server and to use it with websockets (basic websockets, not Flask or something else).所以我试图创建某种 python 服务器并将它与 websockets(基本 websockets,而不是 Flask 或其他东西)一起使用。 I've found this question and tried to do as in answer, but got no result.我找到了这个问题,并试图按照答案做,但没有结果。 Here is code part where I create server and turn it on:这是我创建服务器并将其打开的代码部分:

start_server = websockets.serve(hello, '0.0.0.0', os.environ['PORT'])

asyncio.get_event_loop().run_until_complete(start_server)

and here are heroku logs:这是heroku日志:

2020-02-02T19:15:18.488771+00:00 app[web.1]: [2020-02-02 19:15:18 +0000] [4] [INFO] Starting gunicorn 20.0.4
2020-02-02T19:15:18.489318+00:00 app[web.1]: [2020-02-02 19:15:18 +0000] [4] [INFO] Listening at: http://0.0.0.0:55677 (4)
2020-02-02T19:15:18.489403+00:00 app[web.1]: [2020-02-02 19:15:18 +0000] [4] [INFO] Using worker: sync
2020-02-02T19:15:18.493327+00:00 app[web.1]: [2020-02-02 19:15:18 +0000] [10] [INFO] Booting worker with pid: 10
2020-02-02T19:15:18.503354+00:00 app[web.1]: [2020-02-02 19:15:18 +0000] [11] [INFO] Booting worker with pid: 11
2020-02-02T19:15:18.598218+00:00 app[web.1]: [2020-02-02 19:15:18 +0000] [10] [ERROR] Exception in worker process
2020-02-02T19:15:18.598222+00:00 app[web.1]: Traceback (most recent call last):
2020-02-02T19:15:18.598223+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/asyncio/base_events.py", line 1073, in create_server
2020-02-02T19:15:18.598225+00:00 app[web.1]: sock.bind(sa)
2020-02-02T19:15:18.598226+00:00 app[web.1]: OSError: [Errno 98] Address already in use
2020-02-02T19:15:18.598228+00:00 app[web.1]:
2020-02-02T19:15:18.598229+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2020-02-02T19:15:18.598230+00:00 app[web.1]:
2020-02-02T19:15:18.598232+00:00 app[web.1]: Traceback (most recent call last):
2020-02-02T19:15:18.598247+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2020-02-02T19:15:18.598249+00:00 app[web.1]: worker.init_process()
2020-02-02T19:15:18.598250+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 119, in init_process
2020-02-02T19:15:18.598251+00:00 app[web.1]: self.load_wsgi()
2020-02-02T19:15:18.598253+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
2020-02-02T19:15:18.598254+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2020-02-02T19:15:18.598255+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2020-02-02T19:15:18.598257+00:00 app[web.1]: self.callable = self.load()
2020-02-02T19:15:18.598259+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
2020-02-02T19:15:18.598260+00:00 app[web.1]: return self.load_wsgiapp()
2020-02-02T19:15:18.598261+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
2020-02-02T19:15:18.598263+00:00 app[web.1]: return util.import_app(self.app_uri)
2020-02-02T19:15:18.598264+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 358, in import_app
2020-02-02T19:15:18.598265+00:00 app[web.1]: mod = importlib.import_module(module)
2020-02-02T19:15:18.598267+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
2020-02-02T19:15:18.598268+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2020-02-02T19:15:18.598270+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 994, in _gcd_import
2020-02-02T19:15:18.598271+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 971, in _find_and_load
2020-02-02T19:15:18.598273+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
2020-02-02T19:15:18.598274+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
2020-02-02T19:15:18.598275+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 678, in exec_module
2020-02-02T19:15:18.598277+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2020-02-02T19:15:18.598278+00:00 app[web.1]: File "/app/run_server.py", line 27, in <module>
2020-02-02T19:15:18.598279+00:00 app[web.1]: asyncio.get_event_loop().run_until_complete(start_server)
2020-02-02T19:15:18.598281+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/asyncio/base_events.py", line 488, in run_until_complete
2020-02-02T19:15:18.598282+00:00 app[web.1]: return future.result()
2020-02-02T19:15:18.598284+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/asyncio/tasks.py", line 537, in _wrap_awaitable
2020-02-02T19:15:18.598285+00:00 app[web.1]: return (yield from awaitable.__await__())
2020-02-02T19:15:18.598287+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/websockets/server.py", line 965, in __await_impl__
2020-02-02T19:15:18.598288+00:00 app[web.1]: server = await self._create_server()
2020-02-02T19:15:18.598290+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/asyncio/base_events.py", line 1077, in create_server
2020-02-02T19:15:18.598291+00:00 app[web.1]: % (sa, err.strerror.lower()))
2020-02-02T19:15:18.598293+00:00 app[web.1]: OSError: [Errno 98] error while attempting to bind on address ('0.0.0.0', 55677): address already in use
2020-02-02T19:15:18.598565+00:00 app[web.1]: [2020-02-02 19:15:18 +0000] [10] [INFO] Worker exiting (pid: 10)
2020-02-02T19:15:18.601037+00:00 app[web.1]: [2020-02-02 19:15:18 +0000] [11] [ERROR] Exception in worker process
2020-02-02T19:15:18.601039+00:00 app[web.1]: Traceback (most recent call last):
2020-02-02T19:15:18.601041+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/asyncio/base_events.py", line 1073, in create_server
2020-02-02T19:15:18.601042+00:00 app[web.1]: sock.bind(sa)
2020-02-02T19:15:18.601044+00:00 app[web.1]: OSError: [Errno 98] Address already in use
2020-02-02T19:15:18.601045+00:00 app[web.1]:
2020-02-02T19:15:18.601047+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2020-02-02T19:15:18.601048+00:00 app[web.1]:
2020-02-02T19:15:18.601050+00:00 app[web.1]: Traceback (most recent call last):
2020-02-02T19:15:18.601052+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2020-02-02T19:15:18.601053+00:00 app[web.1]: worker.init_process()
2020-02-02T19:15:18.601055+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 119, in init_process
2020-02-02T19:15:18.601056+00:00 app[web.1]: self.load_wsgi()
2020-02-02T19:15:18.601058+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
2020-02-02T19:15:18.601059+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2020-02-02T19:15:18.601061+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2020-02-02T19:15:18.601062+00:00 app[web.1]: self.callable = self.load()
2020-02-02T19:15:18.601063+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
2020-02-02T19:15:18.601065+00:00 app[web.1]: return self.load_wsgiapp()
2020-02-02T19:15:18.601066+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
2020-02-02T19:15:18.601068+00:00 app[web.1]: return util.import_app(self.app_uri)
2020-02-02T19:15:18.601069+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 358, in import_app
2020-02-02T19:15:18.601070+00:00 app[web.1]: mod = importlib.import_module(module)
2020-02-02T19:15:18.601072+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
2020-02-02T19:15:18.601073+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2020-02-02T19:15:18.601075+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 994, in _gcd_import
2020-02-02T19:15:18.601076+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 971, in _find_and_load
2020-02-02T19:15:18.601078+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
2020-02-02T19:15:18.601079+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
2020-02-02T19:15:18.601081+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 678, in exec_module
2020-02-02T19:15:18.601082+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2020-02-02T19:15:18.601083+00:00 app[web.1]: File "/app/run_server.py", line 27, in <module>
2020-02-02T19:15:18.601085+00:00 app[web.1]: asyncio.get_event_loop().run_until_complete(start_server)
2020-02-02T19:15:18.601086+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/asyncio/base_events.py", line 488, in run_until_complete
2020-02-02T19:15:18.601087+00:00 app[web.1]: return future.result()
2020-02-02T19:15:18.601089+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/asyncio/tasks.py", line 537, in _wrap_awaitable
2020-02-02T19:15:18.601090+00:00 app[web.1]: return (yield from awaitable.__await__())
2020-02-02T19:15:18.601092+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/websockets/server.py", line 965, in __await_impl__
2020-02-02T19:15:18.601093+00:00 app[web.1]: server = await self._create_server()
2020-02-02T19:15:18.601095+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/asyncio/base_events.py", line 1077, in create_server
2020-02-02T19:15:18.601096+00:00 app[web.1]: % (sa, err.strerror.lower()))
2020-02-02T19:15:18.601098+00:00 app[web.1]: OSError: [Errno 98] error while attempting to bind on address ('0.0.0.0', 55677): address already in use
2020-02-02T19:15:18.601406+00:00 app[web.1]: [2020-02-02 19:15:18 +0000] [11] [INFO] Worker exiting (pid: 11)
2020-02-02T19:15:18.639228+00:00 app[web.1]: Traceback (most recent call last):
2020-02-02T19:15:18.639258+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 209, in run
2020-02-02T19:15:18.639550+00:00 app[web.1]: self.sleep()
2020-02-02T19:15:18.639556+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 357, in sleep
2020-02-02T19:15:18.639766+00:00 app[web.1]: ready = select.select([self.PIPE[0]], [], [], 1.0)
2020-02-02T19:15:18.639771+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 242, in handle_chld
2020-02-02T19:15:18.639932+00:00 app[web.1]: self.reap_workers()
2020-02-02T19:15:18.639937+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
2020-02-02T19:15:18.640169+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2020-02-02T19:15:18.640215+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2020-02-02T19:15:18.640221+00:00 app[web.1]:
2020-02-02T19:15:18.640223+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2020-02-02T19:15:18.640224+00:00 app[web.1]:
2020-02-02T19:15:18.640227+00:00 app[web.1]: Traceback (most recent call last):
2020-02-02T19:15:18.640231+00:00 app[web.1]: File "/app/.heroku/python/bin/gunicorn", line 11, in <module>
2020-02-02T19:15:18.640350+00:00 app[web.1]: sys.exit(run())
2020-02-02T19:15:18.640355+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 58, in run
2020-02-02T19:15:18.640522+00:00 app[web.1]: WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
2020-02-02T19:15:18.640527+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 228, in run
2020-02-02T19:15:18.640698+00:00 app[web.1]: super().run()
2020-02-02T19:15:18.640702+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 72, in run
2020-02-02T19:15:18.640826+00:00 app[web.1]: Arbiter(self).run()
2020-02-02T19:15:18.640831+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 229, in run
2020-02-02T19:15:18.640986+00:00 app[web.1]: self.halt(reason=inst.reason, exit_status=inst.exit_status)
2020-02-02T19:15:18.640990+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 342, in halt
2020-02-02T19:15:18.641179+00:00 app[web.1]: self.stop()
2020-02-02T19:15:18.641183+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 393, in stop
2020-02-02T19:15:18.641381+00:00 app[web.1]: time.sleep(0.1)
2020-02-02T19:15:18.641385+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 242, in handle_chld
2020-02-02T19:15:18.641543+00:00 app[web.1]: self.reap_workers()
2020-02-02T19:15:18.641547+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
2020-02-02T19:15:18.641774+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2020-02-02T19:15:18.641801+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2020-02-02T19:15:19.000000+00:00 app[api]: Build succeeded

If I understand correctly, I need to stop process that is currently running on that port and I just don't know how.如果我理解正确,我需要停止当前在该端口上运行的进程,但我不知道如何停止。

So I forgot to mention that I was using gunicorn to run my app, so my Procfile was所以我忘了提到我正在使用gunicorn来运行我的应用程序,所以我的Procfile

web: gunicorn run_server:server

and in the logs you can see that gunicorn listens on needed port, which is why it can't be accessed later (or I think so).在日志中,您可以看到gunicorn侦听所需的端口,这就是为什么以后无法访问它的原因(或者我认为是这样)。

2020-02-02T19:15:18.489318+00:00 app[web.1]: [2020-02-02 19:15:18 +0000] [4] [INFO] Listening at: http://0.0.0.0:55677

I changed my Procfile to我将我的Procfile更改为

web: python run_server.py $PORT

and now it's all good.现在一切都好了。 Thank you for ideas.谢谢你的想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 OSError: [Errno 98] 地址已被使用 - Heroku - OSError: [Errno 98] Address already in use - Heroku Heroku 应用程序错误:OSError:[Errno 98] 地址已在使用中 - Heroku Application Error: OSError: [Errno 98] Address already in use OSError: [Errno 98] 地址已在使用中 - OSError: [Errno 98] Address already in use Python OSError: [Errno 98] 地址已在使用但未使用端口 - Python OSError: [Errno 98] Address already in use but no port is used 面临错误:OSError:[Errno 98] 地址已在使用中:('',8089) - Facing error : OSError: [Errno 98] Address already in use: ('', 8089) Python 套接字 OSError: [Errno 98] 地址已在使用中 - Python socket OSError: [Errno 98] Address already in use Flask Google Cloud App Engine:OSError:[Errno 98] 地址已在使用中 - Flask Google Cloud App Engine: OSError: [Errno 98] Address already in use Flask make_server 总是引发“OSError:[Errno 98] 地址已在使用中” - Flask make_server always raises "OSError: [Errno 98] Address already in use" OSError: [Errno 98] Address already in use Running Flask Application on Apache2 - OSError: [Errno 98] Address already in use Running Flask Application on Apache2 在 colab 上运行 netron 时,出现“OSError: [Errno 98] Address already in use”错误 - while running netron on colab, getting this “OSError: [Errno 98] Address already in use” error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM