This question already has answers here:
Python - How to run multiple flask apps from same client machine
                                
                                    (2个答案)
                                
                        
                                2年前关闭。
            
                    
我正在尝试从Mac终端设置服务器。我已经在端口5000上建立了连接,并想在5002中打开另一个端口。
导航到文件夹位置后:

python Blockchain.py -p 5002


但这给出了一个错误:

OSError: [Errno 48] Address already in use


我在同一问题上提到了各种答案:

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

[Flask and Pycharm socket.error

[Python - Socket Error, Address In Use

另外,我尝试了以下方法来解决此问题:


重新启动终端
重新启动PyCharm
在不同的套接字上运行(给出相同的错误)。


这些似乎都不起作用。我对Python相当陌生。错误消息如下:
python Blockchain.py -p 5002Traceback (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

任何帮助表示赞赏。

[1]:socket.error:[Errno 48]地址已在使用中

[2]:烧瓶和Pycharm socket.error

[3]:Python-套接字错误,正在使用地址

最佳答案

如果您仔细查看回溯,您会看到

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


这意味着无论-p传入什么端口,端口5000都是硬编码的。

您将需要对其进行修改,以使用脚本将-p参数存储为的任何变量。

关于python - OSError:[Errno 48]地址已在使用中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51309895/

10-13 05:08