socket.error:[Errno 48]地址已在使用中(socket.error: [Errno 48] Address already in use)

编程入门 行业动态 更新时间:2024-10-21 03:38:11
socket.error:[Errno 48]地址已在使用中(socket.error: [Errno 48] Address already in use)

我试图从mac终端设置一个带有python的服务器。

我导航到文件夹位置使用:

python -m SimpleHTTPServer

但这给我错误:

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

以前我已经使用相同的命令为我的机器中不同位置的不同网站打开了一个连接。

I'm trying to set up a server with python from mac terminal.

I navigate to folder location an use:

python -m SimpleHTTPServer

But this gives me error:

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

I had previously open a connection using the same command for a different website in a different location in my machine.

最满意答案

您已经有一个流程绑定到默认端口(8000)。 如果您之前已经运行过相同的模块,则很可能该进程仍然绑定到端口。 首先尝试找到另一个进程:

$ ps -fA | grep python 501 81651 12648 0 9:53PM ttys000 0:00.16 python -m SimpleHTTPServer

包含命令参数,因此如果多个python进程处于活动状态,您可以查看运行SimpleHTTPServer参数。 您可能想测试http://localhost:8000/仍然显示本地文件的目录列表。

第二个数字是过程编号; 通过发送信号来停止服务器:

kill 81651

这发送标准SIGTERM信号; 如果进程无响应,则可能需要采取更严格的方法,例如发送SIGKILL ( kill -s KILL <pid>或kill -9 <pid> )信号。 更多详情请参阅维基百科 。

或者,通过在命令行中指定备用端口,在另一个端口上运行服务器:

$ python -m SimpleHTTPServer 8910 Serving HTTP on 0.0.0.0 port 8910 ...

然后访问服务器http://localhost:8910 ; 其中8910可以是从1024及以上的任何数字,只要端口尚未被占用。

You already have a process bound to the default port (8000). If you already ran the same module before, it is most likely that process still bound to the port. Try and locate the other process first:

$ ps -fA | grep python 501 81651 12648 0 9:53PM ttys000 0:00.16 python -m SimpleHTTPServer

The command arguments are included, so you can spot the one running SimpleHTTPServer if more than one python process is active. You may want to test if http://localhost:8000/ still shows a directory listing for local files.

The second number is the process number; stop the server by sending it a signal:

kill 81651

This sends a standard SIGTERM signal; if the process is unresponsive you may have to resort to tougher methods like sending a SIGKILL (kill -s KILL <pid> or kill -9 <pid>) signal instead. See Wikipedia for more details.

Alternatively, run the server on a different port, by specifying the alternative port on the command line:

$ python -m SimpleHTTPServer 8910 Serving HTTP on 0.0.0.0 port 8910 ...

then access the server as http://localhost:8910; where 8910 can be any number from 1024 and up, provided the port is not already taken.

更多推荐

本文发布于:2023-08-01 19:08:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1363733.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:已在   地址   error   socket   Errno

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!