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

查看:31
本文介绍了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 kill -9 ;) 信号代替.请参阅维基百科了解更多详情.

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天全站免登陆