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

查看:105
本文介绍了socket.error:[Errno 48]地址已在使用中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Mac终端使用python设置服务器.

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

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

I navigate to folder location an use:

python -m SimpleHTTPServer

但是这给了我错误:

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)的进程.如果您之前已经运行过相同的模块,则很有可能该进程仍绑定到该端口.首先尝试找到其他进程:

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

包含命令参数,因此,如果有多个python进程处于活动状态,则可以发现正在运行的SimpleHTTPServer.您可能想测试http://localhost:8000/是否仍显示本地文件的目录列表.

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

这会发送标准的SIGTERM信号;如果该过程无响应,则可能不得不采用更严格的方法,例如发送SIGKILL(kill -s KILL <pid>kill -9 <pid>)信号.有关更多详细信息,请参见维基百科.

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 ...

然后以http://localhost:8910身份访问服务器;如果端口尚未使用,则8910可以是1024至更高的任何数字.

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.

这篇关于socket.error:[Errno 48]地址已在使用中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆