简体   繁体   English

Python-套接字错误,正在使用地址

[英]Python - Socket Error, Address In Use

I'm currently attempting to setup a SiriServer (that's beside the point) on Xubuntu 12.10 x64, when I run the server python returns error 我正在尝试在Xubuntu 12.10 x64上设置一个SiriServer(就在这一点上),当我运行服务器时python返回错误

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

The server by default is attempting to run on port 443, which unfortunetly is required in order for this application to work. 默认情况下,服务器正在尝试在端口443上运行,为了使此应用程序正常工作,这是非常需要的。

To double check if anything is running on port 443, I execute the following: 要仔细检查端口443上是否有任何内容,我执行以下命令:

lsof -i :443

There's no results, unless I have something like Chrome or Firefox open, which I end up closing. 没有结果,除非我打开Chrome或Firefox这样的东西,我最终会关闭。 Here's the full return from attempting to run the server application. 这是尝试运行服务器应用程序的全部回报。

dustin@dustin-xubuntu:~/Applications/SiriServer$ sudo python siriServer.py
CRITICAL load_plugins Failed loading plugin due to missing module: 'Wordnik library not found. Please install wordnik library! e.g. sudo easy_install wordnik'
INFO <module> Starting Server
Traceback (most recent call last):
  File "siriServer.py", line 493, in <module>
    server = SiriServer('', options.port)
  File "siriServer.py", line 425, in __init__
    self.bind((host, port))
  File "/usr/lib/python2.7/asyncore.py", line 342, in bind
    return self.socket.bind(addr)
  File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 98] Address already in use

I'm stuck on what to do, as this is the last part of setting up this application. 我坚持要做什么,因为这是设置此应用程序的最后一部分。 Any help is appreciated. 任何帮助表示赞赏。

You're not root -- that's your problem. 你不是根 - 这是你的问题。 To bind to ports under 1024 on Unix, you must be the superuser. 要绑定到Unix下1024以下的端口,您必须是超级用户。 So, hit su and try the python code again. 所以,点击su并再次尝试python代码。 Alternatively, bind to a port from 1024 to 65535. 或者,绑定到1024到65535之间的端口。

This often happens when a python program doesn't exit properly when pressing ^C or ^Z. 当按^ C或^ Z无法正常退出python程序时,通常会发生这种情况。 You could try reseting the terminal or exiting the terminal. 您可以尝试重置终端或退出终端。 You can also do killall -9 server.py 你也可以做killall -9 server.py

Another effective way to help prevent this even if you have root privs this can happen if a socket is not closed properly, here is a fix: 另一种有效的方法来帮助防止这种情况,即使你有root权限这可能会发生如果套接字没有正确关闭,这是一个修复:

s=socket.socket( )
s.bind(("0.0.0.0", 8080))
while 1:
    try:
        c, addr = s.accept()
    except KeyBoardInterrupt:
        s.close()
        exit(0)

I got that error even if port number is more than 1024 即使端口号超过1024,我也收到了该错误

You can use 您可以使用

    pkill -9 python

run command twice, it will list all python files which are killed 运行命令两次,它将列出所有被杀死的python文件

List all processes that you have running with 列出您运行时使用的所有进程

ps -a

Take the PID corresponding to python and pipe it into the kill command with (Example PID 2770) 取对应于python的PID并将其通过管道传递给kill命令(示例PID 2770)

kill -9 2770

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python 中的“socket.error:[Errno 48] 地址已在使用中” - “socket.error: [Errno 48] Address already in use” in Python 套接字错误:地址已在使用中 - Socket error: Address already in use python套接字重定向服务器-socket.error:(98,“地址已在使用中”) - python socket redirect server - socket.error: (98, 'Address already in use') Python:绑定套接字:“地址已在使用中” - Python: Binding Socket: "Address already in use" Errno 98:地址已在使用 - Python Socket - Errno 98: Address already in use - Python Socket 如何在Python中使用coreclty解决ZMQ套接字错误“ zmq.error.ZMQError:地址正在使用” - How to coreclty solve ZMQ socket error “zmq.error.ZMQError: Address in use” in python Python绑定套接字:关闭套接字后,“地址已在使用中” - Python Binding Socket: “Address already in use”, after closing socket 在同一脚本 (python) 中使用套接字服务器和 Flask 网络服务器时地址已在使用错误 - Address already in use error when using a socket server and a flask webserver in the same script (python) python -m SimpleHTTPServer 8000 socket.error: [Errno 98] 地址已被使用 - python -m SimpleHTTPServer 8000 socket.error: [Errno 98] Address already in use 我正在尝试在 Socket (Python) 上使用 IPv6 地址 - I am trying to use IPv6 address on Socket (Python)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM