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

时间:2018-07-12 15:50:09

标签: python sockets ssl flask pycharm

我正在尝试从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

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

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

这似乎都不起作用。我对Python相当陌生。错误消息如下: 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

感谢您的帮助。

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

[2]:烧瓶和Pycharm套接字。错误

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

2 个答案:

答案 0 :(得分:0)

如果您仔细观察回溯,将会看到

DROP TABLE IF EXISTS #Temp11;
GO

CREATE TABLE #Temp11
(
    Field1              INT,
    Date1               DATE,
    Status1             VARCHAR(50),
    Status2             VARCHAR(50),
    Status3             VARCHAR(50),
    Status4             VARCHAR(50),
    ConcatStatus        VARCHAR(1000)
)


INSERT INTO #Temp11 VALUES(111 , '2018-01-05' , 'Yes' , 'Yes' , 'Yes' , 'Yes','');
INSERT INTO #Temp11 VALUES(111 , '2018-01-06' , 'Yes' , 'Yes' , 'Yes' , 'Yes','');
INSERT INTO #Temp11 VALUES(111 , '2018-01-07' , 'Yes' , 'Yes' , 'Yes' , 'Yes','');

INSERT INTO #Temp11 VALUES(111 , '2018-01-11' , 'No' , 'No' , 'No' , 'No','');
INSERT INTO #Temp11 VALUES(111 , '2018-01-12' , 'Yes' , 'Yes' , 'Yes' , 'Yes','');
INSERT INTO #Temp11 VALUES(111 , '2018-01-13' , 'No' , 'No' , 'No' , 'No','');

INSERT INTO #Temp11 VALUES(111 , '2018-01-17' , 'No' , 'No' , 'No' , 'No','');
INSERT INTO #Temp11 VALUES(111 , '2018-01-18' , 'No' , 'No' , 'No' , 'No','');
INSERT INTO #Temp11 VALUES(111 , '2018-01-19' , 'No' , 'No' , 'No' , 'No','');
GO

SELECT * FROM #Temp11;
GO

WITH
    ordered AS (
        SELECT  Field1 ,
                Date1 ,
                Status1 ,
                Status2 ,
                Status3 ,
                Status4 ,
                ROW_NUMBER() OVER (PARTITION BY Field1 ORDER BY Date1) AS RowNumber
        FROM    #Temp11
    ) ,
    combined AS (
        SELECT  Field1 ,
                Date1 ,
                CAST(NULL AS Date) AS Date2 ,
                Status1 ,
                Status2 ,
                Status3 ,
                Status4 ,
                RowNumber
        FROM    ordered
        WHERE   RowNumber = 1
        UNION ALL
        SELECT  o.Field1 ,
                CASE WHEN o.Status1 = c.Status1 AND o.Status2 = c.Status2 AND o.Status3 = c.Status3 AND o.Status4 = c.Status4
                    THEN c.Date1 ELSE o.Date1 END ,
                CASE WHEN o.Status1 = c.Status1 AND o.Status2 = c.Status2 AND o.Status3 = c.Status3 AND o.Status4 = c.Status4
                    THEN o.Date1 ELSE NULL END ,
                o.Status1 ,
                o.Status2 ,
                o.Status3 ,
                o.Status4 ,
                o.RowNumber
        FROM    ordered o
        INNER JOIN combined c
                ON c.Field1 = o.Field1
                AND c.RowNumber = o.RowNumber - 1
    ) ,
    results AS (
        SELECT  Field1 ,
                Date1 ,
                Date2 ,
                Status1 ,
                Status2 ,
                Status3 ,
                Status4 ,
                ROW_NUMBER() OVER (PARTITION BY Field1, Date1 ORDER BY Date2 DESC) AS RowNumber
        FROM    combined
    )
SELECT  Field1 ,
        Date1 ,
        Date2 ,
        Status1,
        Status2,
        Status3,
        Status4
FROM    results
WHERE   RowNumber = 1
ORDER BY Field1 ,
        Date1

这意味着无论app.run(host='0.0.0.0', port=5000) 传入哪个端口,端口5000都是硬编码的。

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

答案 1 :(得分:0)

在尝试实现DeepSpace建议的答案时,我偶然发现了以下答案:

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

要在不同的计算机上运行Flask应用程序,请使用:

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

打开另一个终端并使用:

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

积分:https://stackoverflow.com/users/5802335/metmirr