Reputation: 557
OSError: [Errno 10048] error while attempting to bind on address ('0.0.0.0', 8080): only one usage of e
ach socket address (protocol/network address/port) is normally permitted
I have installed aiohttp and as mentioned in a tutorial,
I tried to run the script using
python main.py
command
from aiohttp import web
async def index(request):
return web.Response(text='Hello Aiohttp!')
app = web.Application()
web.run_app(app)
I get this error and don't know how to sort this issue.
Any kind of help is appreciated
Upvotes: 2
Views: 23095
Reputation: 31
Issue with your problem is some process is already running on 8080 port number. There are two ways to solve problem
sudo kill `sudo lsof -t -i:8080` (if you are working on ubuntu) or
sudo kill $(sudo lsof -t -i:8080)
python -m aiohttp.web -H localhost -P 5050 package.module.init_func
package.module.init_func
should be an importable callable that accepts a list of any non-parsed command-line arguments and returns an Application
instance after setting it up:
def init_function(argv):
app = web.Application()
app.router.add_route("GET", "/", index_handler)
return app
hopefully above solution may will help you.
you can go through documentation of aiohttp to know more about it. https://aiohttp.readthedocs.io/en/v0.21.5/web.html
Upvotes: 3
Reputation: 1216
From the documentation https://aiohttp.readthedocs.io/en/stable/web_reference.html#aiohttp.web.run_app .You can pass the port as
from aiohttp import web
async def index(request):
return web.Response(text='Hello Aiohttp!')
app = web.Application()
web.run_app(app, port=9090)
Upvotes: 2