[Solved] OSError: [Errno 48] Address already in use [duplicate]

I’m trying to setup a server from Mac terminal. I’ve established a connection on port 5000 and want to open another port in 5002.
After navigating to the folder location:

python Blockchain.py -p 5002

But this gives an error:

OSError: [Errno 48] Address already in use

I’ve referred various answers on the same issue:

[socket.error: [Errno 48] Address already in use

[Flask and Pycharm socket.error

[Python – Socket Error, Address In Use

Also, I tried the following methods to resolve the issue:

  1. Restarting the terminals
  2. Restarting PyCharm
  3. Running on different sockets (gives same error).

None of that seems to work. I’m fairly new to Python. Error message attached below:
python Blockchain.py -p 5002
Traceback (most recent call last):
File "Blockchain.py", line 290, in <module>
app.run(host="0.0.0.0", port=5000)
File "/anaconda/envs/blockchain/lib/python3.6/site-packages/flask/app.py", line 841, in run
run_simple(host, port, self, **options)
File "/anaconda/envs/blockchain/lib/python3.6/site-packages/werkzeug/serving.py", line 814, in run_simple
inner()
File "/anaconda/envs/blockchain/lib/python3.6/site-packages/werkzeug/serving.py", line 774, in inner
fd=fd)
File "/anaconda/envs/blockchain/lib/python3.6/site-packages/werkzeug/serving.py", line 666, in make_server
passthrough_errors, ssl_context, fd=fd)
File "/anaconda/envs/blockchain/lib/python3.6/site-packages/werkzeug/serving.py", line 577, in __init__
self.address_family), handler)
File "/anaconda/envs/blockchain/lib/python3.6/socketserver.py", line 453, in __init__
self.server_bind()
File "/anaconda/envs/blockchain/lib/python3.6/http/server.py", line 136, in server_bind
socketserver.TCPServer.server_bind(self)
File "/anaconda/envs/blockchain/lib/python3.6/socketserver.py", line 467, in server_bind
self.socket.bind(self.server_address)
OSError: [Errno 48] Address already in use

Any help is appreciated.

[1]: socket.error: [Errno 48] Address already in use

[2]: Flask and Pycharm socket.error

[3]: Python – Socket Error, Address In Use

Solution #1:

If you look closely at the traceback you will see

app.run(host='0.0.0.0', port=5000)

which means that no matter what port is passed in by -p, port 5000 is hardcoded.

You will need to modify it to use whatever variable the script is storing the -p argument as.

Respondent: Prashant Mahajan

Solution #2:

While trying to implement answer suggested by DeepSpace I stumbled across the following answer:

https://stackoverflow.com/questions/48205495/python-how-to-run-multiple-flask-apps-from-same-client-machine

To run Flask application on different machines use:

 $ export FLASK_APP=Blockchain.py
 $ flask run --host 0.0.0.0 --port 5000

Open up another terminal and use:

$ export FLASK_APP=Blockchain.py
$ flask run --host 0.0.0.0 --port 5001

Credits: https://stackoverflow.com/users/5802335/metmirr

Respondent: DeepSpace

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.