英文:
What Python exception does 'OSError: [Errno 98] Address already in use' cause
问题
I want to catch the specific exception listed above, what do I need to put after except
to do that?
我想捕获上面列出的特定异常,在except
之后需要放什么?
英文:
I'm writing a basic Python TCP socket server. I want to catch the specific exception listed above, what do I need to put after except
to do that?
答案1
得分: 1
"Its the OSError, so you need to catch OSError:"
except OSError as error:
print(error)
英文:
Its the OSError, so you need to catch OSError:
except OSError as error:
print(error)
答案2
得分: 1
错误的意思是有一个现有的进程正在使用与您在代码中使用的相同的IP地址和端口。
回答您最初的问题,这是如何在Python中处理此异常的方式:
try:
# 在这里放入您的代码
except OSError as error:
print(error)
然而,这不会解决您的问题,捕获错误也没有太多意义(除非您想要优雅地退出并显示一条消息)。您只需在任务管理器中找到使用相同地址的进程并将其终止。
英文:
The error means that there is an existing process using the same ip address and port that you're using within your code.
To answer your initial question, this is how you would handle this exception in Python:
try :
#your code here
except OSError as error :
print(error)
Nevertheless, this will not solve your issue, and it doesn't make much sense to catch the error (only if you want to exit gracefully and show a message maybe). You just need to find the process which is using the same address in your task manager and kill it.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论